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

Side by Side Diff: runtime/vm/object.cc

Issue 154393003: Implement eager instantiation and canonicalization of type arguments at run (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // These are initialized to a value that will force a illegal memory access if 82 // These are initialized to a value that will force a illegal memory access if
83 // they are being used. 83 // they are being used.
84 #if defined(RAW_NULL) 84 #if defined(RAW_NULL)
85 #error RAW_NULL should not be defined. 85 #error RAW_NULL should not be defined.
86 #endif 86 #endif
87 #define RAW_NULL kHeapObjectTag 87 #define RAW_NULL kHeapObjectTag
88 Object* Object::null_object_ = NULL; 88 Object* Object::null_object_ = NULL;
89 Array* Object::null_array_ = NULL; 89 Array* Object::null_array_ = NULL;
90 String* Object::null_string_ = NULL; 90 String* Object::null_string_ = NULL;
91 Instance* Object::null_instance_ = NULL; 91 Instance* Object::null_instance_ = NULL;
92 AbstractTypeArguments* Object::null_abstract_type_arguments_ = NULL; 92 TypeArguments* Object::null_type_arguments_ = NULL;
93 Array* Object::empty_array_ = NULL; 93 Array* Object::empty_array_ = NULL;
94 PcDescriptors* Object::empty_descriptors_ = NULL; 94 PcDescriptors* Object::empty_descriptors_ = NULL;
95 Instance* Object::sentinel_ = NULL; 95 Instance* Object::sentinel_ = NULL;
96 Instance* Object::transition_sentinel_ = NULL; 96 Instance* Object::transition_sentinel_ = NULL;
97 Instance* Object::unknown_constant_ = NULL; 97 Instance* Object::unknown_constant_ = NULL;
98 Instance* Object::non_constant_ = NULL; 98 Instance* Object::non_constant_ = NULL;
99 Bool* Object::bool_true_ = NULL; 99 Bool* Object::bool_true_ = NULL;
100 Bool* Object::bool_false_ = NULL; 100 Bool* Object::bool_false_ = NULL;
101 Smi* Object::smi_illegal_cid_ = NULL; 101 Smi* Object::smi_illegal_cid_ = NULL;
102 LanguageError* Object::snapshot_writer_error_ = NULL; 102 LanguageError* Object::snapshot_writer_error_ = NULL;
103 LanguageError* Object::branch_offset_error_ = NULL; 103 LanguageError* Object::branch_offset_error_ = NULL;
104 104
105 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL); 105 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL);
106 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 106 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
107 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 107 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
108 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 108 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
109 RawType* Object::dynamic_type_ = reinterpret_cast<RawType*>(RAW_NULL); 109 RawType* Object::dynamic_type_ = reinterpret_cast<RawType*>(RAW_NULL);
110 RawType* Object::void_type_ = reinterpret_cast<RawType*>(RAW_NULL); 110 RawType* Object::void_type_ = reinterpret_cast<RawType*>(RAW_NULL);
111 RawClass* Object::unresolved_class_class_ = 111 RawClass* Object::unresolved_class_class_ =
112 reinterpret_cast<RawClass*>(RAW_NULL); 112 reinterpret_cast<RawClass*>(RAW_NULL);
113 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 113 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
114 RawClass* Object::instantiated_type_arguments_class_ =
115 reinterpret_cast<RawClass*>(RAW_NULL);
116 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 114 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
117 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 115 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
118 RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 116 RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
119 RawClass* Object::redirection_data_class_ = 117 RawClass* Object::redirection_data_class_ =
120 reinterpret_cast<RawClass*>(RAW_NULL); 118 reinterpret_cast<RawClass*>(RAW_NULL);
121 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 119 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
122 RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 120 RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
123 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 121 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
124 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 122 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
125 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 123 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 } 438 }
441 439
442 Isolate* isolate = Isolate::Current(); 440 Isolate* isolate = Isolate::Current();
443 Heap* heap = isolate->heap(); 441 Heap* heap = isolate->heap();
444 442
445 // Allocate the read only object handles here. 443 // Allocate the read only object handles here.
446 null_object_ = Object::ReadOnlyHandle(); 444 null_object_ = Object::ReadOnlyHandle();
447 null_array_ = Array::ReadOnlyHandle(); 445 null_array_ = Array::ReadOnlyHandle();
448 null_string_ = String::ReadOnlyHandle(); 446 null_string_ = String::ReadOnlyHandle();
449 null_instance_ = Instance::ReadOnlyHandle(); 447 null_instance_ = Instance::ReadOnlyHandle();
450 null_abstract_type_arguments_ = AbstractTypeArguments::ReadOnlyHandle(); 448 null_type_arguments_ = TypeArguments::ReadOnlyHandle();
451 empty_array_ = Array::ReadOnlyHandle(); 449 empty_array_ = Array::ReadOnlyHandle();
452 empty_descriptors_ = PcDescriptors::ReadOnlyHandle(); 450 empty_descriptors_ = PcDescriptors::ReadOnlyHandle();
453 sentinel_ = Instance::ReadOnlyHandle(); 451 sentinel_ = Instance::ReadOnlyHandle();
454 transition_sentinel_ = Instance::ReadOnlyHandle(); 452 transition_sentinel_ = Instance::ReadOnlyHandle();
455 unknown_constant_ = Instance::ReadOnlyHandle(); 453 unknown_constant_ = Instance::ReadOnlyHandle();
456 non_constant_ = Instance::ReadOnlyHandle(); 454 non_constant_ = Instance::ReadOnlyHandle();
457 bool_true_ = Bool::ReadOnlyHandle(); 455 bool_true_ = Bool::ReadOnlyHandle();
458 bool_false_ = Bool::ReadOnlyHandle(); 456 bool_false_ = Bool::ReadOnlyHandle();
459 smi_illegal_cid_ = Smi::ReadOnlyHandle(); 457 smi_illegal_cid_ = Smi::ReadOnlyHandle();
460 snapshot_writer_error_ = LanguageError::ReadOnlyHandle(); 458 snapshot_writer_error_ = LanguageError::ReadOnlyHandle();
461 branch_offset_error_ = LanguageError::ReadOnlyHandle(); 459 branch_offset_error_ = LanguageError::ReadOnlyHandle();
462 460
463 461
464 // Allocate and initialize the null instance. 462 // Allocate and initialize the null instance.
465 // 'null_' must be the first object allocated as it is used in allocation to 463 // 'null_' must be the first object allocated as it is used in allocation to
466 // clear the object. 464 // clear the object.
467 { 465 {
468 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); 466 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld);
469 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); 467 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag);
470 // The call below is using 'null_' to initialize itself. 468 // The call below is using 'null_' to initialize itself.
471 InitializeObject(address, kNullCid, Instance::InstanceSize()); 469 InitializeObject(address, kNullCid, Instance::InstanceSize());
472 } 470 }
473 471
474 *null_object_ = Object::null(); 472 *null_object_ = Object::null();
475 *null_array_ = Array::null(); 473 *null_array_ = Array::null();
476 *null_string_ = String::null(); 474 *null_string_ = String::null();
477 *null_instance_ = Instance::null(); 475 *null_instance_ = Instance::null();
478 *null_abstract_type_arguments_ = AbstractTypeArguments::null(); 476 *null_type_arguments_ = TypeArguments::null();
479 477
480 // Initialize the empty array handle to null_ in order to be able to check 478 // Initialize the empty array handle to null_ in order to be able to check
481 // if the empty array was allocated (RAW_NULL is not available). 479 // if the empty array was allocated (RAW_NULL is not available).
482 *empty_array_ = Array::null(); 480 *empty_array_ = Array::null();
483 481
484 Class& cls = Class::Handle(); 482 Class& cls = Class::Handle();
485 483
486 // Allocate and initialize the class class. 484 // Allocate and initialize the class class.
487 { 485 {
488 intptr_t size = Class::InstanceSize(); 486 intptr_t size = Class::InstanceSize();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); 538 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld);
541 } 539 }
542 540
543 // Allocate the remaining VM internal classes. 541 // Allocate the remaining VM internal classes.
544 cls = Class::New<UnresolvedClass>(); 542 cls = Class::New<UnresolvedClass>();
545 unresolved_class_class_ = cls.raw(); 543 unresolved_class_class_ = cls.raw();
546 544
547 cls = Class::New<TypeArguments>(); 545 cls = Class::New<TypeArguments>();
548 type_arguments_class_ = cls.raw(); 546 type_arguments_class_ = cls.raw();
549 547
550 cls = Class::New<InstantiatedTypeArguments>();
551 instantiated_type_arguments_class_ = cls.raw();
552
553 cls = Class::New<PatchClass>(); 548 cls = Class::New<PatchClass>();
554 patch_class_class_ = cls.raw(); 549 patch_class_class_ = cls.raw();
555 550
556 cls = Class::New<Function>(); 551 cls = Class::New<Function>();
557 function_class_ = cls.raw(); 552 function_class_ = cls.raw();
558 553
559 cls = Class::New<ClosureData>(); 554 cls = Class::New<ClosureData>();
560 closure_data_class_ = cls.raw(); 555 closure_data_class_ = cls.raw();
561 556
562 cls = Class::New<RedirectionData>(); 557 cls = Class::New<RedirectionData>();
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 error_str = String::New("Branch offset overflow"); 707 error_str = String::New("Branch offset overflow");
713 *branch_offset_error_ = LanguageError::New(error_str); 708 *branch_offset_error_ = LanguageError::New(error_str);
714 709
715 ASSERT(!null_object_->IsSmi()); 710 ASSERT(!null_object_->IsSmi());
716 ASSERT(!null_array_->IsSmi()); 711 ASSERT(!null_array_->IsSmi());
717 ASSERT(null_array_->IsArray()); 712 ASSERT(null_array_->IsArray());
718 ASSERT(!null_string_->IsSmi()); 713 ASSERT(!null_string_->IsSmi());
719 ASSERT(null_string_->IsString()); 714 ASSERT(null_string_->IsString());
720 ASSERT(!null_instance_->IsSmi()); 715 ASSERT(!null_instance_->IsSmi());
721 ASSERT(null_instance_->IsInstance()); 716 ASSERT(null_instance_->IsInstance());
722 ASSERT(!null_abstract_type_arguments_->IsSmi()); 717 ASSERT(!null_type_arguments_->IsSmi());
723 ASSERT(null_abstract_type_arguments_->IsAbstractTypeArguments()); 718 ASSERT(null_type_arguments_->IsTypeArguments());
724 ASSERT(!empty_array_->IsSmi()); 719 ASSERT(!empty_array_->IsSmi());
725 ASSERT(empty_array_->IsArray()); 720 ASSERT(empty_array_->IsArray());
726 ASSERT(!sentinel_->IsSmi()); 721 ASSERT(!sentinel_->IsSmi());
727 ASSERT(sentinel_->IsInstance()); 722 ASSERT(sentinel_->IsInstance());
728 ASSERT(!transition_sentinel_->IsSmi()); 723 ASSERT(!transition_sentinel_->IsSmi());
729 ASSERT(transition_sentinel_->IsInstance()); 724 ASSERT(transition_sentinel_->IsInstance());
730 ASSERT(!unknown_constant_->IsSmi()); 725 ASSERT(!unknown_constant_->IsSmi());
731 ASSERT(unknown_constant_->IsInstance()); 726 ASSERT(unknown_constant_->IsInstance());
732 ASSERT(!non_constant_->IsSmi()); 727 ASSERT(!non_constant_->IsSmi());
733 ASSERT(non_constant_->IsInstance()); 728 ASSERT(non_constant_->IsInstance());
(...skipping 15 matching lines...) Expand all
749 744
750 void Object::RegisterSingletonClassNames() { 745 void Object::RegisterSingletonClassNames() {
751 Class& cls = Class::Handle(); 746 Class& cls = Class::Handle();
752 747
753 // Set up names for all VM singleton classes. 748 // Set up names for all VM singleton classes.
754 SET_CLASS_NAME(class, Class); 749 SET_CLASS_NAME(class, Class);
755 SET_CLASS_NAME(dynamic, Dynamic); 750 SET_CLASS_NAME(dynamic, Dynamic);
756 SET_CLASS_NAME(void, Void); 751 SET_CLASS_NAME(void, Void);
757 SET_CLASS_NAME(unresolved_class, UnresolvedClass); 752 SET_CLASS_NAME(unresolved_class, UnresolvedClass);
758 SET_CLASS_NAME(type_arguments, TypeArguments); 753 SET_CLASS_NAME(type_arguments, TypeArguments);
759 SET_CLASS_NAME(instantiated_type_arguments, InstantiatedTypeArguments);
760 SET_CLASS_NAME(patch_class, PatchClass); 754 SET_CLASS_NAME(patch_class, PatchClass);
761 SET_CLASS_NAME(function, Function); 755 SET_CLASS_NAME(function, Function);
762 SET_CLASS_NAME(closure_data, ClosureData); 756 SET_CLASS_NAME(closure_data, ClosureData);
763 SET_CLASS_NAME(redirection_data, RedirectionData); 757 SET_CLASS_NAME(redirection_data, RedirectionData);
764 SET_CLASS_NAME(field, Field); 758 SET_CLASS_NAME(field, Field);
765 SET_CLASS_NAME(literal_token, LiteralToken); 759 SET_CLASS_NAME(literal_token, LiteralToken);
766 SET_CLASS_NAME(token_stream, TokenStream); 760 SET_CLASS_NAME(token_stream, TokenStream);
767 SET_CLASS_NAME(script, Script); 761 SET_CLASS_NAME(script, Script);
768 SET_CLASS_NAME(library, LibraryClass); 762 SET_CLASS_NAME(library, LibraryClass);
769 SET_CLASS_NAME(library_prefix, LibraryPrefix); 763 SET_CLASS_NAME(library_prefix, LibraryPrefix);
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1620 1614
1621 // Return the still unfinalized signature type. 1615 // Return the still unfinalized signature type.
1622 ASSERT(!signature_type.IsFinalized()); 1616 ASSERT(!signature_type.IsFinalized());
1623 return signature_type.raw(); 1617 return signature_type.raw();
1624 } 1618 }
1625 1619
1626 1620
1627 RawAbstractType* Class::RareType() const { 1621 RawAbstractType* Class::RareType() const {
1628 const Type& type = Type::Handle(Type::New( 1622 const Type& type = Type::Handle(Type::New(
1629 *this, 1623 *this,
1630 Object::null_abstract_type_arguments(), 1624 Object::null_type_arguments(),
1631 Scanner::kNoSourcePos)); 1625 Scanner::kNoSourcePos));
1632 return ClassFinalizer::FinalizeType(*this, 1626 return ClassFinalizer::FinalizeType(*this,
1633 type, 1627 type,
1634 ClassFinalizer::kCanonicalize); 1628 ClassFinalizer::kCanonicalize);
1635 } 1629 }
1636 1630
1637 1631
1638 RawAbstractType* Class::DeclarationType() const { 1632 RawAbstractType* Class::DeclarationType() const {
1639 const TypeArguments& args = TypeArguments::Handle(type_parameters()); 1633 const TypeArguments& args = TypeArguments::Handle(type_parameters());
1640 const Type& type = Type::Handle(Type::New( 1634 const Type& type = Type::Handle(Type::New(
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 if (!FLAG_overlap_type_arguments || 2021 if (!FLAG_overlap_type_arguments ||
2028 (num_type_params == 0) || 2022 (num_type_params == 0) ||
2029 (super_type() == AbstractType::null()) || 2023 (super_type() == AbstractType::null()) ||
2030 (super_type() == isolate->object_store()->object_type())) { 2024 (super_type() == isolate->object_store()->object_type())) {
2031 set_num_own_type_arguments(num_type_params); 2025 set_num_own_type_arguments(num_type_params);
2032 return num_type_params; 2026 return num_type_params;
2033 } 2027 }
2034 ASSERT(!IsMixinApplication() || is_mixin_type_applied()); 2028 ASSERT(!IsMixinApplication() || is_mixin_type_applied());
2035 const AbstractType& sup_type = AbstractType::Handle(isolate, super_type()); 2029 const AbstractType& sup_type = AbstractType::Handle(isolate, super_type());
2036 ASSERT(sup_type.IsResolved()); 2030 ASSERT(sup_type.IsResolved());
2037 const AbstractTypeArguments& sup_type_args = 2031 const TypeArguments& sup_type_args =
2038 AbstractTypeArguments::Handle(isolate, sup_type.arguments()); 2032 TypeArguments::Handle(isolate, sup_type.arguments());
2039 if (sup_type_args.IsNull()) { 2033 if (sup_type_args.IsNull()) {
2040 // The super type is raw or the super class is non generic. 2034 // The super type is raw or the super class is non generic.
2041 // In either case, overlapping is not possible. 2035 // In either case, overlapping is not possible.
2042 set_num_own_type_arguments(num_type_params); 2036 set_num_own_type_arguments(num_type_params);
2043 return num_type_params; 2037 return num_type_params;
2044 } 2038 }
2045 const intptr_t num_sup_type_args = sup_type_args.Length(); 2039 const intptr_t num_sup_type_args = sup_type_args.Length();
2046 // At this point, the super type may or may not be finalized. In either case, 2040 // At this point, the super type may or may not be finalized. In either case,
2047 // the result of this function must remain the same. 2041 // the result of this function must remain the same.
2048 // The value of num_sup_type_args may increase when the super type is 2042 // The value of num_sup_type_args may increase when the super type is
2049 // finalized, but the last num_sup_type_args type arguments will not be 2043 // finalized, but the last num_sup_type_args type arguments will not be
2050 // modified by finalization, only shifted to higher indices in the vector. 2044 // modified by finalization, only shifted to higher indices in the vector.
2051 // They may however get wrapped in a BoundedType, which we skip. 2045 // They may however get wrapped in a BoundedType, which we skip.
2052 const AbstractTypeArguments& type_params = 2046 const TypeArguments& type_params =
2053 AbstractTypeArguments::Handle(isolate, type_parameters()); 2047 TypeArguments::Handle(isolate, type_parameters());
2054 // Determine the maximum overlap of a prefix of the vector consisting of the 2048 // Determine the maximum overlap of a prefix of the vector consisting of the
2055 // type parameters of this class with a suffix of the vector consisting of the 2049 // type parameters of this class with a suffix of the vector consisting of the
2056 // type arguments of the super type of this class. 2050 // type arguments of the super type of this class.
2057 // The number of own type arguments of this class is the number of its type 2051 // The number of own type arguments of this class is the number of its type
2058 // parameters minus the number of type arguments in the overlap. 2052 // parameters minus the number of type arguments in the overlap.
2059 // Attempt to overlap the whole vector of type parameters; reduce the size 2053 // Attempt to overlap the whole vector of type parameters; reduce the size
2060 // of the vector (keeping the first type parameter) until it fits or until 2054 // of the vector (keeping the first type parameter) until it fits or until
2061 // its size is zero. 2055 // its size is zero.
2062 TypeParameter& type_param = TypeParameter::Handle(isolate); 2056 TypeParameter& type_param = TypeParameter::Handle(isolate);
2063 AbstractType& sup_type_arg = AbstractType::Handle(isolate); 2057 AbstractType& sup_type_arg = AbstractType::Handle(isolate);
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after
2934 case kDynamicCid: 2928 case kDynamicCid:
2935 return Symbols::Dynamic().raw(); 2929 return Symbols::Dynamic().raw();
2936 case kVoidCid: 2930 case kVoidCid:
2937 return Symbols::Void().raw(); 2931 return Symbols::Void().raw();
2938 case kClassCid: 2932 case kClassCid:
2939 return Symbols::Class().raw(); 2933 return Symbols::Class().raw();
2940 case kUnresolvedClassCid: 2934 case kUnresolvedClassCid:
2941 return Symbols::UnresolvedClass().raw(); 2935 return Symbols::UnresolvedClass().raw();
2942 case kTypeArgumentsCid: 2936 case kTypeArgumentsCid:
2943 return Symbols::TypeArguments().raw(); 2937 return Symbols::TypeArguments().raw();
2944 case kInstantiatedTypeArgumentsCid:
2945 return Symbols::InstantiatedTypeArguments().raw();
2946 case kPatchClassCid: 2938 case kPatchClassCid:
2947 return Symbols::PatchClass().raw(); 2939 return Symbols::PatchClass().raw();
2948 case kFunctionCid: 2940 case kFunctionCid:
2949 return Symbols::Function().raw(); 2941 return Symbols::Function().raw();
2950 case kClosureDataCid: 2942 case kClosureDataCid:
2951 return Symbols::ClosureData().raw(); 2943 return Symbols::ClosureData().raw();
2952 case kRedirectionDataCid: 2944 case kRedirectionDataCid:
2953 return Symbols::RedirectionData().raw(); 2945 return Symbols::RedirectionData().raw();
2954 case kFieldCid: 2946 case kFieldCid:
2955 return Symbols::Field().raw(); 2947 return Symbols::Field().raw();
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
3230 return (!function.IsNull() && (function.signature_class() == raw())); 3222 return (!function.IsNull() && (function.signature_class() == raw()));
3231 } 3223 }
3232 3224
3233 3225
3234 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T. 3226 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T.
3235 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T. 3227 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T.
3236 // Type S is specified by this class parameterized with 'type_arguments', and 3228 // Type S is specified by this class parameterized with 'type_arguments', and
3237 // type T by class 'other' parameterized with 'other_type_arguments'. 3229 // type T by class 'other' parameterized with 'other_type_arguments'.
3238 // This class and class 'other' do not need to be finalized, however, they must 3230 // This class and class 'other' do not need to be finalized, however, they must
3239 // be resolved as well as their interfaces. 3231 // be resolved as well as their interfaces.
3240 bool Class::TypeTestNonRecursive( 3232 bool Class::TypeTestNonRecursive(const Class& cls,
3241 const Class& cls, 3233 Class::TypeTestKind test_kind,
3242 Class::TypeTestKind test_kind, 3234 const TypeArguments& type_arguments,
3243 const AbstractTypeArguments& type_arguments, 3235 const Class& other,
3244 const Class& other, 3236 const TypeArguments& other_type_arguments,
3245 const AbstractTypeArguments& other_type_arguments, 3237 Error* bound_error) {
3246 Error* bound_error) {
3247 // Use the thsi object as if it was the receiver of this method, but instead 3238 // Use the thsi object as if it was the receiver of this method, but instead
3248 // of recursing reset it to the super class and loop. 3239 // of recursing reset it to the super class and loop.
3249 Class& thsi = Class::Handle(cls.raw()); 3240 Class& thsi = Class::Handle(cls.raw());
3250 while (true) { 3241 while (true) {
3251 ASSERT(!thsi.IsVoidClass()); 3242 ASSERT(!thsi.IsVoidClass());
3252 // Check for DynamicType. 3243 // Check for DynamicType.
3253 // Each occurrence of DynamicType in type T is interpreted as the dynamic 3244 // Each occurrence of DynamicType in type T is interpreted as the dynamic
3254 // type, a supertype of all types. 3245 // type, a supertype of all types.
3255 if (other.IsDynamicClass()) { 3246 if (other.IsDynamicClass()) {
3256 return true; 3247 return true;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
3336 bound_error)) { 3327 bound_error)) {
3337 return true; 3328 return true;
3338 } 3329 }
3339 } 3330 }
3340 } 3331 }
3341 // Check for 'direct super type' specified in the implements clause 3332 // Check for 'direct super type' specified in the implements clause
3342 // and check for transitivity at the same time. 3333 // and check for transitivity at the same time.
3343 Array& interfaces = Array::Handle(thsi.interfaces()); 3334 Array& interfaces = Array::Handle(thsi.interfaces());
3344 AbstractType& interface = AbstractType::Handle(); 3335 AbstractType& interface = AbstractType::Handle();
3345 Class& interface_class = Class::Handle(); 3336 Class& interface_class = Class::Handle();
3346 AbstractTypeArguments& interface_args = AbstractTypeArguments::Handle(); 3337 TypeArguments& interface_args = TypeArguments::Handle();
3347 Error& error = Error::Handle(); 3338 Error& error = Error::Handle();
3348 for (intptr_t i = 0; i < interfaces.Length(); i++) { 3339 for (intptr_t i = 0; i < interfaces.Length(); i++) {
3349 interface ^= interfaces.At(i); 3340 interface ^= interfaces.At(i);
3350 if (!interface.IsFinalized()) { 3341 if (!interface.IsFinalized()) {
3351 // We may be checking bounds at finalization time and can encounter 3342 // We may be checking bounds at finalization time and can encounter
3352 // a still unfinalized interface. 3343 // a still unfinalized interface.
3353 ClassFinalizer::FinalizeType( 3344 ClassFinalizer::FinalizeType(
3354 thsi, interface, ClassFinalizer::kCanonicalize); 3345 thsi, interface, ClassFinalizer::kCanonicalize);
3355 interfaces.SetAt(i, interface); 3346 interfaces.SetAt(i, interface);
3356 } 3347 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3400 return false; 3391 return false;
3401 } 3392 }
3402 3393
3403 3394
3404 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T. 3395 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T.
3405 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T. 3396 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T.
3406 // Type S is specified by this class parameterized with 'type_arguments', and 3397 // Type S is specified by this class parameterized with 'type_arguments', and
3407 // type T by class 'other' parameterized with 'other_type_arguments'. 3398 // type T by class 'other' parameterized with 'other_type_arguments'.
3408 // This class and class 'other' do not need to be finalized, however, they must 3399 // This class and class 'other' do not need to be finalized, however, they must
3409 // be resolved as well as their interfaces. 3400 // be resolved as well as their interfaces.
3410 bool Class::TypeTest( 3401 bool Class::TypeTest(TypeTestKind test_kind,
3411 TypeTestKind test_kind, 3402 const TypeArguments& type_arguments,
3412 const AbstractTypeArguments& type_arguments,
3413 const Class& other, 3403 const Class& other,
3414 const AbstractTypeArguments& other_type_arguments, 3404 const TypeArguments& other_type_arguments,
3415 Error* bound_error) const { 3405 Error* bound_error) const {
3416 return TypeTestNonRecursive(*this, 3406 return TypeTestNonRecursive(*this,
3417 test_kind, 3407 test_kind,
3418 type_arguments, 3408 type_arguments,
3419 other, 3409 other,
3420 other_type_arguments, 3410 other_type_arguments,
3421 bound_error); 3411 bound_error);
3422 } 3412 }
3423 3413
3424 3414
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
3847 OS::SNPrint(chars, len, format, cname); 3837 OS::SNPrint(chars, len, format, cname);
3848 return chars; 3838 return chars;
3849 } 3839 }
3850 3840
3851 3841
3852 void UnresolvedClass::PrintToJSONStream(JSONStream* stream, bool ref) const { 3842 void UnresolvedClass::PrintToJSONStream(JSONStream* stream, bool ref) const {
3853 JSONObject jsobj(stream); 3843 JSONObject jsobj(stream);
3854 } 3844 }
3855 3845
3856 3846
3857 intptr_t AbstractTypeArguments::Length() const {
3858 // AbstractTypeArguments is an abstract class.
3859 UNREACHABLE();
3860 return -1;
3861 }
3862
3863
3864 RawAbstractType* AbstractTypeArguments::TypeAt(intptr_t index) const {
3865 // AbstractTypeArguments is an abstract class.
3866 UNREACHABLE();
3867 return NULL;
3868 }
3869
3870
3871 void AbstractTypeArguments::SetTypeAt(intptr_t index,
3872 const AbstractType& value) const {
3873 // AbstractTypeArguments is an abstract class.
3874 UNREACHABLE();
3875 }
3876
3877
3878 bool AbstractTypeArguments::IsResolved() const {
3879 // AbstractTypeArguments is an abstract class.
3880 UNREACHABLE();
3881 return false;
3882 }
3883
3884
3885 bool AbstractTypeArguments::IsInstantiated(GrowableObjectArray* trail) const {
3886 // AbstractTypeArguments is an abstract class.
3887 UNREACHABLE();
3888 return false;
3889 }
3890
3891
3892 bool AbstractTypeArguments::IsUninstantiatedIdentity() const {
3893 // AbstractTypeArguments is an abstract class.
3894 UNREACHABLE();
3895 return false;
3896 }
3897
3898
3899 bool AbstractTypeArguments::CanShareInstantiatorTypeArguments(
3900 const Class& instantiator_class) const {
3901 // AbstractTypeArguments is an abstract class.
3902 UNREACHABLE();
3903 return false;
3904 }
3905
3906
3907 bool AbstractTypeArguments::IsBounded() const {
3908 // AbstractTypeArguments is an abstract class.
3909 UNREACHABLE();
3910 return false;
3911 }
3912
3913
3914 static intptr_t FinalizeHash(uword hash) { 3847 static intptr_t FinalizeHash(uword hash) {
3915 hash += hash << 3; 3848 hash += hash << 3;
3916 hash ^= hash >> 11; 3849 hash ^= hash >> 11;
3917 hash += hash << 15; 3850 hash += hash << 15;
3918 return hash; 3851 return hash;
3919 } 3852 }
3920 3853
3921 3854
3922 intptr_t AbstractTypeArguments::Hash() const { 3855 intptr_t TypeArguments::Hash() const {
3923 if (IsNull()) return 0; 3856 if (IsNull()) return 0;
3924 uword result = 0; 3857 uword result = 0;
3925 const intptr_t num_types = Length(); 3858 const intptr_t num_types = Length();
3926 AbstractType& type = AbstractType::Handle(); 3859 AbstractType& type = AbstractType::Handle();
3927 for (intptr_t i = 0; i < num_types; i++) { 3860 for (intptr_t i = 0; i < num_types; i++) {
3928 type = TypeAt(i); 3861 type = TypeAt(i);
3929 result += type.Hash(); 3862 result += type.Hash();
3930 result += result << 10; 3863 result += result << 10;
3931 result ^= result >> 6; 3864 result ^= result >> 6;
3932 } 3865 }
3933 return FinalizeHash(result); 3866 return FinalizeHash(result);
3934 } 3867 }
3935 3868
3936 3869
3937 RawString* AbstractTypeArguments::SubvectorName( 3870 RawString* TypeArguments::SubvectorName(intptr_t from_index,
3938 intptr_t from_index, 3871 intptr_t len,
3939 intptr_t len, 3872 NameVisibility name_visibility) const {
3940 NameVisibility name_visibility) const {
3941 ASSERT(from_index + len <= Length()); 3873 ASSERT(from_index + len <= Length());
3942 String& name = String::Handle(); 3874 String& name = String::Handle();
3943 const intptr_t num_strings = 2*len + 1; // "<""T"", ""T"">". 3875 const intptr_t num_strings = 2*len + 1; // "<""T"", ""T"">".
3944 const Array& strings = Array::Handle(Array::New(num_strings)); 3876 const Array& strings = Array::Handle(Array::New(num_strings));
3945 intptr_t s = 0; 3877 intptr_t s = 0;
3946 strings.SetAt(s++, Symbols::LAngleBracket()); 3878 strings.SetAt(s++, Symbols::LAngleBracket());
3947 AbstractType& type = AbstractType::Handle(); 3879 AbstractType& type = AbstractType::Handle();
3948 for (intptr_t i = 0; i < len; i++) { 3880 for (intptr_t i = 0; i < len; i++) {
3949 type = TypeAt(from_index + i); 3881 type = TypeAt(from_index + i);
3950 name = type.BuildName(name_visibility); 3882 name = type.BuildName(name_visibility);
3951 strings.SetAt(s++, name); 3883 strings.SetAt(s++, name);
3952 if (i < len - 1) { 3884 if (i < len - 1) {
3953 strings.SetAt(s++, Symbols::CommaSpace()); 3885 strings.SetAt(s++, Symbols::CommaSpace());
3954 } 3886 }
3955 } 3887 }
3956 strings.SetAt(s++, Symbols::RAngleBracket()); 3888 strings.SetAt(s++, Symbols::RAngleBracket());
3957 ASSERT(s == num_strings); 3889 ASSERT(s == num_strings);
3958 name = String::ConcatAll(strings); 3890 name = String::ConcatAll(strings);
3959 return Symbols::New(name); 3891 return Symbols::New(name);
3960 } 3892 }
3961 3893
3962 3894
3963 bool AbstractTypeArguments::IsEquivalent(const AbstractTypeArguments& other, 3895 bool TypeArguments::IsEquivalent(const TypeArguments& other,
3964 GrowableObjectArray* trail) const { 3896 GrowableObjectArray* trail) const {
3965 if (this->raw() == other.raw()) { 3897 if (this->raw() == other.raw()) {
3966 return true; 3898 return true;
3967 } 3899 }
3968 if (IsNull() || other.IsNull()) { 3900 if (IsNull() || other.IsNull()) {
3969 return false; 3901 return false;
3970 } 3902 }
3971 const intptr_t num_types = Length(); 3903 const intptr_t num_types = Length();
3972 if (num_types != other.Length()) { 3904 if (num_types != other.Length()) {
3973 return false; 3905 return false;
3974 } 3906 }
3975 AbstractType& type = AbstractType::Handle(); 3907 AbstractType& type = AbstractType::Handle();
3976 AbstractType& other_type = AbstractType::Handle(); 3908 AbstractType& other_type = AbstractType::Handle();
3977 for (intptr_t i = 0; i < num_types; i++) { 3909 for (intptr_t i = 0; i < num_types; i++) {
3978 type = TypeAt(i); 3910 type = TypeAt(i);
3979 other_type = other.TypeAt(i); 3911 other_type = other.TypeAt(i);
3980 if (!type.IsEquivalent(other_type, trail)) { 3912 if (!type.IsEquivalent(other_type, trail)) {
3981 return false; 3913 return false;
3982 } 3914 }
3983 } 3915 }
3984 return true; 3916 return true;
3985 } 3917 }
3986 3918
3987 3919
3988 RawAbstractTypeArguments* AbstractTypeArguments::InstantiateFrom( 3920 bool TypeArguments::IsDynamicTypes(bool raw_instantiated,
3989 const AbstractTypeArguments& instantiator_type_arguments, 3921 intptr_t from_index,
3990 Error* bound_error, 3922 intptr_t len) const {
3991 GrowableObjectArray* trail) const {
3992 // AbstractTypeArguments is an abstract class.
3993 UNREACHABLE();
3994 return NULL;
3995 }
3996
3997
3998 bool AbstractTypeArguments::IsDynamicTypes(bool raw_instantiated,
3999 intptr_t from_index,
4000 intptr_t len) const {
4001 ASSERT(Length() >= (from_index + len)); 3923 ASSERT(Length() >= (from_index + len));
4002 AbstractType& type = AbstractType::Handle(); 3924 AbstractType& type = AbstractType::Handle();
4003 Class& type_class = Class::Handle(); 3925 Class& type_class = Class::Handle();
4004 for (intptr_t i = 0; i < len; i++) { 3926 for (intptr_t i = 0; i < len; i++) {
4005 type = TypeAt(from_index + i); 3927 type = TypeAt(from_index + i);
4006 ASSERT(!type.IsNull()); 3928 ASSERT(!type.IsNull());
4007 if (!type.HasResolvedTypeClass()) { 3929 if (!type.HasResolvedTypeClass()) {
4008 if (raw_instantiated && type.IsTypeParameter()) { 3930 if (raw_instantiated && type.IsTypeParameter()) {
4009 // An uninstantiated type parameter is equivalent to dynamic (even in 3931 // An uninstantiated type parameter is equivalent to dynamic (even in
4010 // the presence of a malformed bound in checked mode). 3932 // the presence of a malformed bound in checked mode).
4011 continue; 3933 continue;
4012 } 3934 }
4013 return false; 3935 return false;
4014 } 3936 }
4015 type_class = type.type_class(); 3937 type_class = type.type_class();
4016 if (!type_class.IsDynamicClass()) { 3938 if (!type_class.IsDynamicClass()) {
4017 return false; 3939 return false;
4018 } 3940 }
4019 } 3941 }
4020 return true; 3942 return true;
4021 } 3943 }
4022 3944
4023 3945
4024 bool AbstractTypeArguments::TypeTest(TypeTestKind test_kind, 3946 bool TypeArguments::TypeTest(TypeTestKind test_kind,
4025 const AbstractTypeArguments& other, 3947 const TypeArguments& other,
4026 intptr_t from_index, 3948 intptr_t from_index,
4027 intptr_t len, 3949 intptr_t len,
4028 Error* bound_error) const { 3950 Error* bound_error) const {
4029 ASSERT(Length() >= (from_index + len)); 3951 ASSERT(Length() >= (from_index + len));
4030 ASSERT(!other.IsNull()); 3952 ASSERT(!other.IsNull());
4031 ASSERT(other.Length() >= (from_index + len)); 3953 ASSERT(other.Length() >= (from_index + len));
4032 AbstractType& type = AbstractType::Handle(); 3954 AbstractType& type = AbstractType::Handle();
4033 AbstractType& other_type = AbstractType::Handle(); 3955 AbstractType& other_type = AbstractType::Handle();
4034 for (intptr_t i = 0; i < len; i++) { 3956 for (intptr_t i = 0; i < len; i++) {
4035 type = TypeAt(from_index + i); 3957 type = TypeAt(from_index + i);
4036 ASSERT(!type.IsNull()); 3958 ASSERT(!type.IsNull());
4037 other_type = other.TypeAt(from_index + i); 3959 other_type = other.TypeAt(from_index + i);
4038 ASSERT(!other_type.IsNull()); 3960 ASSERT(!other_type.IsNull());
4039 if (!type.TypeTest(test_kind, other_type, bound_error)) { 3961 if (!type.TypeTest(test_kind, other_type, bound_error)) {
4040 return false; 3962 return false;
4041 } 3963 }
4042 } 3964 }
4043 return true; 3965 return true;
4044 } 3966 }
4045 3967
4046 3968
4047 const char* AbstractTypeArguments::ToCString() const { 3969 void TypeArguments::PrintToJSONStream(JSONStream* stream, bool ref) const {
4048 // AbstractTypeArguments is an abstract class, valid only for representing 3970 JSONObject jsobj(stream);
4049 // null.
4050 if (IsNull()) {
4051 return "NULL AbstractTypeArguments";
4052 }
4053 UNREACHABLE();
4054 return "AbstractTypeArguments";
4055 } 3971 }
4056 3972
4057 3973
4058 void AbstractTypeArguments::PrintToJSONStream(JSONStream* stream, 3974 RawArray* TypeArguments::instantiations() const {
4059 bool ref) const { 3975 return raw_ptr()->instantiations_;
4060 JSONObject jsobj(stream); 3976 }
3977
3978 void TypeArguments::set_instantiations(const Array& value) const {
3979 ASSERT(!value.IsNull());
3980 StorePointer(&raw_ptr()->instantiations_, value.raw());
4061 } 3981 }
4062 3982
4063 3983
4064 intptr_t TypeArguments::Length() const { 3984 intptr_t TypeArguments::Length() const {
4065 ASSERT(!IsNull()); 3985 ASSERT(!IsNull());
4066 return Smi::Value(raw_ptr()->length_); 3986 return Smi::Value(raw_ptr()->length_);
4067 } 3987 }
4068 3988
4069 3989
4070 RawAbstractType* TypeArguments::TypeAt(intptr_t index) const { 3990 RawAbstractType* TypeArguments::TypeAt(intptr_t index) const {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
4185 } 4105 }
4186 } 4106 }
4187 // As a second requirement, the type arguments corresponding to the super type 4107 // As a second requirement, the type arguments corresponding to the super type
4188 // must be identical. Overlapping ones have already been checked starting at 4108 // must be identical. Overlapping ones have already been checked starting at
4189 // first_type_param_offset. 4109 // first_type_param_offset.
4190 if (first_type_param_offset == 0) { 4110 if (first_type_param_offset == 0) {
4191 return true; 4111 return true;
4192 } 4112 }
4193 AbstractType& super_type = AbstractType::Handle( 4113 AbstractType& super_type = AbstractType::Handle(
4194 instantiator_class.super_type()); 4114 instantiator_class.super_type());
4195 const AbstractTypeArguments& super_type_args = AbstractTypeArguments::Handle( 4115 const TypeArguments& super_type_args = TypeArguments::Handle(
4196 super_type.arguments()); 4116 super_type.arguments());
4197 if (super_type_args.IsNull()) { 4117 if (super_type_args.IsNull()) {
4198 return false; 4118 return false;
4199 } 4119 }
4200 AbstractType& super_type_arg = AbstractType::Handle(); 4120 AbstractType& super_type_arg = AbstractType::Handle();
4201 for (intptr_t i = 0; 4121 for (intptr_t i = 0;
4202 (i < first_type_param_offset) && (i < num_type_args); i++) { 4122 (i < first_type_param_offset) && (i < num_type_args); i++) {
4203 type_arg = TypeAt(i); 4123 type_arg = TypeAt(i);
4204 super_type_arg = super_type_args.TypeAt(i); 4124 super_type_arg = super_type_args.TypeAt(i);
4205 if (!type_arg.Equals(super_type_arg)) { 4125 if (!type_arg.Equals(super_type_arg)) {
(...skipping 27 matching lines...) Expand all
4233 return true; 4153 return true;
4234 } 4154 }
4235 if (type.IsTypeParameter()) { 4155 if (type.IsTypeParameter()) {
4236 const AbstractType& bound = AbstractType::Handle( 4156 const AbstractType& bound = AbstractType::Handle(
4237 TypeParameter::Cast(type).bound()); 4157 TypeParameter::Cast(type).bound());
4238 if (!bound.IsObjectType() && !bound.IsDynamicType()) { 4158 if (!bound.IsObjectType() && !bound.IsDynamicType()) {
4239 return true; 4159 return true;
4240 } 4160 }
4241 continue; 4161 continue;
4242 } 4162 }
4243 const AbstractTypeArguments& type_args = AbstractTypeArguments::Handle( 4163 const TypeArguments& type_args = TypeArguments::Handle(
4244 Type::Cast(type).arguments()); 4164 Type::Cast(type).arguments());
4245 if (!type_args.IsNull() && type_args.IsBounded()) { 4165 if (!type_args.IsNull() && type_args.IsBounded()) {
4246 return true; 4166 return true;
4247 } 4167 }
4248 } 4168 }
4249 return false; 4169 return false;
4250 } 4170 }
4251 4171
4252 4172
4253 RawAbstractTypeArguments* TypeArguments::InstantiateFrom( 4173 RawTypeArguments* TypeArguments::InstantiateFrom(
4254 const AbstractTypeArguments& instantiator_type_arguments, 4174 const TypeArguments& instantiator_type_arguments,
4255 Error* bound_error, 4175 Error* bound_error,
4256 GrowableObjectArray* trail) const { 4176 GrowableObjectArray* trail) const {
4257 ASSERT(!IsInstantiated()); 4177 ASSERT(!IsInstantiated());
4258 if (!instantiator_type_arguments.IsNull() && 4178 if (!instantiator_type_arguments.IsNull() &&
4259 IsUninstantiatedIdentity() && 4179 IsUninstantiatedIdentity() &&
4260 (instantiator_type_arguments.Length() == Length())) { 4180 (instantiator_type_arguments.Length() == Length())) {
4261 return instantiator_type_arguments.raw(); 4181 return instantiator_type_arguments.raw();
4262 } 4182 }
4263 const intptr_t num_types = Length(); 4183 const intptr_t num_types = Length();
4264 TypeArguments& instantiated_array = 4184 TypeArguments& instantiated_array =
4265 TypeArguments::Handle(TypeArguments::New(num_types, Heap::kNew)); 4185 TypeArguments::Handle(TypeArguments::New(num_types, Heap::kNew));
4266 AbstractType& type = AbstractType::Handle(); 4186 AbstractType& type = AbstractType::Handle();
4267 for (intptr_t i = 0; i < num_types; i++) { 4187 for (intptr_t i = 0; i < num_types; i++) {
4268 type = TypeAt(i); 4188 type = TypeAt(i);
4269 if (!type.IsBeingFinalized() && !type.IsInstantiated()) { 4189 if (!type.IsBeingFinalized() && !type.IsInstantiated()) {
4270 type = type.InstantiateFrom(instantiator_type_arguments, 4190 type = type.InstantiateFrom(instantiator_type_arguments,
4271 bound_error, 4191 bound_error,
4272 trail); 4192 trail);
4273 } 4193 }
4274 instantiated_array.SetTypeAt(i, type); 4194 instantiated_array.SetTypeAt(i, type);
4275 } 4195 }
4276 return instantiated_array.raw(); 4196 return instantiated_array.raw();
4277 } 4197 }
4278 4198
4279 4199
4200 RawTypeArguments* TypeArguments::InstantiateAndCanonicalizeFrom(
4201 const TypeArguments& instantiator_type_arguments,
4202 Error* bound_error) const {
4203 ASSERT(!IsInstantiated());
4204 ASSERT(instantiator_type_arguments.IsNull() ||
4205 instantiator_type_arguments.IsCanonical());
4206 // Lookup instantiator and, if found, return paired instantiated result.
4207 Array& prior_instantiations = Array::Handle(instantiations());
4208 ASSERT(!prior_instantiations.IsNull());
4209 intptr_t length = prior_instantiations.Length();
4210 intptr_t index = 0;
4211 while (index < length) {
4212 if (prior_instantiations.At(index) == instantiator_type_arguments.raw()) {
4213 return TypeArguments::RawCast(prior_instantiations.At(index + 1));
4214 }
4215 if (prior_instantiations.At(index) == Smi::New(StubCode::kNoInstantiator)) {
4216 break;
4217 }
4218 index += 2;
4219 }
4220 TypeArguments& result = TypeArguments::Handle();
4221 result ^= InstantiateFrom(instantiator_type_arguments, bound_error);
4222 if ((bound_error != NULL) && !bound_error->IsNull()) {
4223 return result.raw();
4224 }
Ivan Posva 2014/02/07 18:48:43 Please add a comment explaining that everything be
regis 2014/02/07 19:42:00 Done.
4225 result ^= result.Canonicalize();
4226 // Add instantiator and result to instantiations array.
4227 if ((index + 2) > length) {
4228 // Grow the instantiations array.
4229 length = (length == 0) ? 2 : length * 2;
srdjan 2014/02/07 17:32:17 The growth seems to aggressive. I would never grow
regis 2014/02/07 19:42:00 Done: length = (length == 0) ? 2 : length + 4;
4230 prior_instantiations =
4231 Array::Grow(prior_instantiations, length, Heap::kOld);
4232 set_instantiations(prior_instantiations);
4233 }
4234 prior_instantiations.SetAt(index, instantiator_type_arguments);
4235 prior_instantiations.SetAt(index + 1, result);
4236 if ((index + 2) < length) {
4237 prior_instantiations.SetAt(index + 2,
4238 Smi::Handle(Smi::New(StubCode::kNoInstantiator)));
4239 }
4240 return result.raw();
4241 }
4242
4243
4280 RawTypeArguments* TypeArguments::New(intptr_t len, Heap::Space space) { 4244 RawTypeArguments* TypeArguments::New(intptr_t len, Heap::Space space) {
4281 if (len < 0 || len > kMaxElements) { 4245 if (len < 0 || len > kMaxElements) {
4282 // This should be caught before we reach here. 4246 // This should be caught before we reach here.
4283 FATAL1("Fatal error in TypeArguments::New: invalid len %" Pd "\n", len); 4247 FATAL1("Fatal error in TypeArguments::New: invalid len %" Pd "\n", len);
4284 } 4248 }
4285 TypeArguments& result = TypeArguments::Handle(); 4249 TypeArguments& result = TypeArguments::Handle();
4286 { 4250 {
4287 RawObject* raw = Object::Allocate(TypeArguments::kClassId, 4251 RawObject* raw = Object::Allocate(TypeArguments::kClassId,
4288 TypeArguments::InstanceSize(len), 4252 TypeArguments::InstanceSize(len),
4289 space); 4253 space);
4290 NoGCScope no_gc; 4254 NoGCScope no_gc;
4291 result ^= raw; 4255 result ^= raw;
4292 // Length must be set before we start storing into the array. 4256 // Length must be set before we start storing into the array.
4293 result.SetLength(len); 4257 result.SetLength(len);
4294 } 4258 }
4259 result.set_instantiations(Object::empty_array());
4295 return result.raw(); 4260 return result.raw();
4296 } 4261 }
4297 4262
4298 4263
4299 4264
4300 RawAbstractType** TypeArguments::TypeAddr(intptr_t index) const { 4265 RawAbstractType** TypeArguments::TypeAddr(intptr_t index) const {
4301 // TODO(iposva): Determine if we should throw an exception here. 4266 // TODO(iposva): Determine if we should throw an exception here.
4302 ASSERT((index >= 0) && (index < Length())); 4267 ASSERT((index >= 0) && (index < Length()));
4303 return &raw_ptr()->types_[index]; 4268 return &raw_ptr()->types_[index];
4304 } 4269 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
4376 TypeArguments& current = TypeArguments::Handle(isolate); 4341 TypeArguments& current = TypeArguments::Handle(isolate);
4377 current ^= table.At(index); 4342 current ^= table.At(index);
4378 while (!current.IsNull() && !current.Equals(arguments)) { 4343 while (!current.IsNull() && !current.Equals(arguments)) {
4379 index = (index + 1) & (table_size - 1); // Move to next element. 4344 index = (index + 1) & (table_size - 1); // Move to next element.
4380 current ^= table.At(index); 4345 current ^= table.At(index);
4381 } 4346 }
4382 return index; // Index of element if found or slot into which to add it. 4347 return index; // Index of element if found or slot into which to add it.
4383 } 4348 }
4384 4349
4385 4350
4386 RawAbstractTypeArguments* TypeArguments::CloneUnfinalized() const { 4351 RawTypeArguments* TypeArguments::CloneUnfinalized() const {
4387 if (IsFinalized()) { 4352 if (IsNull() || IsFinalized()) {
4388 return raw(); 4353 return raw();
4389 } 4354 }
4390 AbstractType& type = AbstractType::Handle(); 4355 AbstractType& type = AbstractType::Handle();
4391 const intptr_t num_types = Length(); 4356 const intptr_t num_types = Length();
4392 const TypeArguments& clone = TypeArguments::Handle( 4357 const TypeArguments& clone = TypeArguments::Handle(
4393 TypeArguments::New(num_types)); 4358 TypeArguments::New(num_types));
4394 for (intptr_t i = 0; i < num_types; i++) { 4359 for (intptr_t i = 0; i < num_types; i++) {
4395 type = TypeAt(i); 4360 type = TypeAt(i);
4396 type = type.CloneUnfinalized(); 4361 type = type.CloneUnfinalized();
4397 clone.SetTypeAt(i, type); 4362 clone.SetTypeAt(i, type);
4398 } 4363 }
4399 return clone.raw(); 4364 return clone.raw();
4400 } 4365 }
4401 4366
4402 4367
4403 RawAbstractTypeArguments* TypeArguments::Canonicalize( 4368 RawTypeArguments* TypeArguments::Canonicalize(
4404 GrowableObjectArray* trail) const { 4369 GrowableObjectArray* trail) const {
4405 if (IsNull() || IsCanonical()) { 4370 if (IsNull() || IsCanonical()) {
4406 ASSERT(IsOld()); 4371 ASSERT(IsOld());
4407 return this->raw(); 4372 return this->raw();
4408 } 4373 }
4409 Isolate* isolate = Isolate::Current(); 4374 Isolate* isolate = Isolate::Current();
4410 ObjectStore* object_store = isolate->object_store(); 4375 ObjectStore* object_store = isolate->object_store();
4411 const Array& table = Array::Handle(isolate, 4376 const Array& table = Array::Handle(isolate,
4412 object_store->canonical_type_arguments()); 4377 object_store->canonical_type_arguments());
4413 ASSERT(table.Length() > 0); 4378 ASSERT(table.Length() > 0);
(...skipping 17 matching lines...) Expand all
4431 result ^= Object::Clone(*this, Heap::kOld); 4396 result ^= Object::Clone(*this, Heap::kOld);
4432 } else { 4397 } else {
4433 result ^= this->raw(); 4398 result ^= this->raw();
4434 } 4399 }
4435 ASSERT(result.IsOld()); 4400 ASSERT(result.IsOld());
4436 InsertIntoCanonicalTypeArguments(isolate, table, result, index); 4401 InsertIntoCanonicalTypeArguments(isolate, table, result, index);
4437 } 4402 }
4438 ASSERT(result.Equals(*this)); 4403 ASSERT(result.Equals(*this));
4439 ASSERT(!result.IsNull()); 4404 ASSERT(!result.IsNull());
4440 ASSERT(result.IsTypeArguments()); 4405 ASSERT(result.IsTypeArguments());
4406 ASSERT(result.IsCanonical());
4441 return result.raw(); 4407 return result.raw();
4442 } 4408 }
4443 4409
4444 4410
4445 const char* TypeArguments::ToCString() const { 4411 const char* TypeArguments::ToCString() const {
4446 if (IsNull()) { 4412 if (IsNull()) {
4447 return "NULL TypeArguments"; 4413 return "NULL TypeArguments";
4448 } 4414 }
4449 const char* format = "%s [%s]"; 4415 const char* format = "%s [%s]";
4450 const char* prev_cstr = "TypeArguments:"; 4416 const char* prev_cstr = "TypeArguments:";
4451 for (int i = 0; i < Length(); i++) { 4417 for (int i = 0; i < Length(); i++) {
4452 const AbstractType& type_at = AbstractType::Handle(TypeAt(i)); 4418 const AbstractType& type_at = AbstractType::Handle(TypeAt(i));
4453 const char* type_cstr = type_at.IsNull() ? "null" : type_at.ToCString(); 4419 const char* type_cstr = type_at.IsNull() ? "null" : type_at.ToCString();
4454 intptr_t len = OS::SNPrint(NULL, 0, format, prev_cstr, type_cstr) + 1; 4420 intptr_t len = OS::SNPrint(NULL, 0, format, prev_cstr, type_cstr) + 1;
4455 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 4421 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
4456 OS::SNPrint(chars, len, format, prev_cstr, type_cstr); 4422 OS::SNPrint(chars, len, format, prev_cstr, type_cstr);
4457 prev_cstr = chars; 4423 prev_cstr = chars;
4458 } 4424 }
4459 return prev_cstr; 4425 return prev_cstr;
4460 } 4426 }
4461 4427
4462 4428
4463 void TypeArguments::PrintToJSONStream(JSONStream* stream, bool ref) const {
4464 JSONObject jsobj(stream);
4465 }
4466
4467
4468 intptr_t InstantiatedTypeArguments::Length() const {
4469 return AbstractTypeArguments::Handle(
4470 uninstantiated_type_arguments()).Length();
4471 }
4472
4473
4474 RawAbstractType* InstantiatedTypeArguments::TypeAt(intptr_t index) const {
4475 AbstractType& type = AbstractType::Handle(AbstractTypeArguments::Handle(
4476 uninstantiated_type_arguments()).TypeAt(index));
4477 if (!type.IsInstantiated()) {
4478 const AbstractTypeArguments& instantiator_type_args =
4479 AbstractTypeArguments::Handle(instantiator_type_arguments());
4480 Error& bound_error = Error::Handle();
4481 type = type.InstantiateFrom(instantiator_type_args, &bound_error);
4482 // InstantiatedTypeArguments cannot include unchecked bounds.
4483 // In the presence of unchecked bounds, no InstantiatedTypeArguments are
4484 // allocated, but the type arguments are instantiated individually and their
4485 // bounds are checked.
4486 ASSERT(bound_error.IsNull());
4487 }
4488 return type.raw();
4489 }
4490
4491
4492 void InstantiatedTypeArguments::SetTypeAt(intptr_t index,
4493 const AbstractType& value) const {
4494 // We only replace individual argument types during resolution at compile
4495 // time, when no type parameters are instantiated yet.
4496 UNREACHABLE();
4497 }
4498
4499
4500 RawAbstractTypeArguments* InstantiatedTypeArguments::Canonicalize(
4501 GrowableObjectArray* trail) const {
4502 const intptr_t num_types = Length();
4503 const TypeArguments& type_args = TypeArguments::Handle(
4504 TypeArguments::New(num_types, Heap::kOld));
4505 AbstractType& type = AbstractType::Handle();
4506 for (intptr_t i = 0; i < num_types; i++) {
4507 type = TypeAt(i);
4508 type_args.SetTypeAt(i, type);
4509 }
4510 return type_args.Canonicalize(trail);
4511 }
4512
4513
4514 void InstantiatedTypeArguments::set_uninstantiated_type_arguments(
4515 const AbstractTypeArguments& value) const {
4516 StorePointer(&raw_ptr()->uninstantiated_type_arguments_, value.raw());
4517 }
4518
4519
4520 void InstantiatedTypeArguments::set_instantiator_type_arguments(
4521 const AbstractTypeArguments& value) const {
4522 StorePointer(&raw_ptr()->instantiator_type_arguments_, value.raw());
4523 }
4524
4525
4526 RawInstantiatedTypeArguments* InstantiatedTypeArguments::New() {
4527 ASSERT(Object::instantiated_type_arguments_class() != Class::null());
4528 RawObject* raw = Object::Allocate(InstantiatedTypeArguments::kClassId,
4529 InstantiatedTypeArguments::InstanceSize(),
4530 Heap::kNew);
4531 return reinterpret_cast<RawInstantiatedTypeArguments*>(raw);
4532 }
4533
4534
4535 RawInstantiatedTypeArguments* InstantiatedTypeArguments::New(
4536 const AbstractTypeArguments& uninstantiated_type_arguments,
4537 const AbstractTypeArguments& instantiator_type_arguments) {
4538 const InstantiatedTypeArguments& result =
4539 InstantiatedTypeArguments::Handle(InstantiatedTypeArguments::New());
4540 result.set_uninstantiated_type_arguments(uninstantiated_type_arguments);
4541 result.set_instantiator_type_arguments(instantiator_type_arguments);
4542 return result.raw();
4543 }
4544
4545
4546 const char* InstantiatedTypeArguments::ToCString() const {
4547 if (IsNull()) {
4548 return "NULL InstantiatedTypeArguments";
4549 }
4550 const char* format = "InstantiatedTypeArguments: [%s] instantiator: [%s]";
4551 const char* arg_cstr =
4552 AbstractTypeArguments::Handle(
4553 uninstantiated_type_arguments()).ToCString();
4554 const char* instantiator_cstr =
4555 AbstractTypeArguments::Handle(instantiator_type_arguments()).ToCString();
4556 intptr_t len =
4557 OS::SNPrint(NULL, 0, format, arg_cstr, instantiator_cstr) + 1;
4558 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
4559 OS::SNPrint(chars, len, format, arg_cstr, instantiator_cstr);
4560 return chars;
4561 }
4562
4563
4564 void InstantiatedTypeArguments::PrintToJSONStream(JSONStream* stream,
4565 bool ref) const {
4566 JSONObject jsobj(stream);
4567 }
4568
4569
4570 const char* PatchClass::ToCString() const { 4429 const char* PatchClass::ToCString() const {
4571 const char* kFormat = "PatchClass for %s"; 4430 const char* kFormat = "PatchClass for %s";
4572 const Class& cls = Class::Handle(patched_class()); 4431 const Class& cls = Class::Handle(patched_class());
4573 const char* cls_name = cls.ToCString(); 4432 const char* cls_name = cls.ToCString();
4574 intptr_t len = OS::SNPrint(NULL, 0, kFormat, cls_name) + 1; 4433 intptr_t len = OS::SNPrint(NULL, 0, kFormat, cls_name) + 1;
4575 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 4434 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
4576 OS::SNPrint(chars, len, kFormat, cls_name); 4435 OS::SNPrint(chars, len, kFormat, cls_name);
4577 return chars; 4436 return chars;
4578 } 4437 }
4579 4438
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
5410 return chars; 5269 return chars;
5411 } 5270 }
5412 5271
5413 5272
5414 bool Function::HasCompatibleParametersWith(const Function& other, 5273 bool Function::HasCompatibleParametersWith(const Function& other,
5415 Error* bound_error) const { 5274 Error* bound_error) const {
5416 ASSERT(FLAG_error_on_bad_override); 5275 ASSERT(FLAG_error_on_bad_override);
5417 ASSERT((bound_error != NULL) && bound_error->IsNull()); 5276 ASSERT((bound_error != NULL) && bound_error->IsNull());
5418 // Check that this function's signature type is a subtype of the other 5277 // Check that this function's signature type is a subtype of the other
5419 // function's signature type. 5278 // function's signature type.
5420 if (!TypeTest(kIsSubtypeOf, Object::null_abstract_type_arguments(), 5279 if (!TypeTest(kIsSubtypeOf, Object::null_type_arguments(),
5421 other, Object::null_abstract_type_arguments(), bound_error)) { 5280 other, Object::null_type_arguments(), bound_error)) {
5422 // For more informative error reporting, use the location of the other 5281 // For more informative error reporting, use the location of the other
5423 // function here, since the caller will use the location of this function. 5282 // function here, since the caller will use the location of this function.
5424 *bound_error = LanguageError::NewFormatted( 5283 *bound_error = LanguageError::NewFormatted(
5425 *bound_error, // A bound error if non null. 5284 *bound_error, // A bound error if non null.
5426 Script::Handle(other.script()), 5285 Script::Handle(other.script()),
5427 other.token_pos(), 5286 other.token_pos(),
5428 LanguageError::kError, 5287 LanguageError::kError,
5429 Heap::kNew, 5288 Heap::kNew,
5430 "signature type '%s' of function '%s' is not a subtype of signature " 5289 "signature type '%s' of function '%s' is not a subtype of signature "
5431 "type '%s' of function '%s'", 5290 "type '%s' of function '%s'",
(...skipping 18 matching lines...) Expand all
5450 // parameter of the other function. 5309 // parameter of the other function.
5451 // If test_kind == kIsMoreSpecificThan, checks if the type of the specified 5310 // If test_kind == kIsMoreSpecificThan, checks if the type of the specified
5452 // parameter of this function is more specific than the type of the specified 5311 // parameter of this function is more specific than the type of the specified
5453 // parameter of the other function. 5312 // parameter of the other function.
5454 // Note that we do not apply contravariance of parameter types, but covariance 5313 // Note that we do not apply contravariance of parameter types, but covariance
5455 // of both parameter types and result type. 5314 // of both parameter types and result type.
5456 bool Function::TestParameterType( 5315 bool Function::TestParameterType(
5457 TypeTestKind test_kind, 5316 TypeTestKind test_kind,
5458 intptr_t parameter_position, 5317 intptr_t parameter_position,
5459 intptr_t other_parameter_position, 5318 intptr_t other_parameter_position,
5460 const AbstractTypeArguments& type_arguments, 5319 const TypeArguments& type_arguments,
5461 const Function& other, 5320 const Function& other,
5462 const AbstractTypeArguments& other_type_arguments, 5321 const TypeArguments& other_type_arguments,
5463 Error* bound_error) const { 5322 Error* bound_error) const {
5464 AbstractType& other_param_type = 5323 AbstractType& other_param_type =
5465 AbstractType::Handle(other.ParameterTypeAt(other_parameter_position)); 5324 AbstractType::Handle(other.ParameterTypeAt(other_parameter_position));
5466 if (!other_param_type.IsInstantiated()) { 5325 if (!other_param_type.IsInstantiated()) {
5467 other_param_type = other_param_type.InstantiateFrom(other_type_arguments, 5326 other_param_type = other_param_type.InstantiateFrom(other_type_arguments,
5468 bound_error); 5327 bound_error);
5469 ASSERT((bound_error == NULL) || bound_error->IsNull()); 5328 ASSERT((bound_error == NULL) || bound_error->IsNull());
5470 } 5329 }
5471 if (other_param_type.IsDynamicType()) { 5330 if (other_param_type.IsDynamicType()) {
5472 return true; 5331 return true;
(...skipping 16 matching lines...) Expand all
5489 ASSERT(test_kind == kIsMoreSpecificThan); 5348 ASSERT(test_kind == kIsMoreSpecificThan);
5490 if (!param_type.IsMoreSpecificThan(other_param_type, bound_error)) { 5349 if (!param_type.IsMoreSpecificThan(other_param_type, bound_error)) {
5491 return false; 5350 return false;
5492 } 5351 }
5493 } 5352 }
5494 return true; 5353 return true;
5495 } 5354 }
5496 5355
5497 5356
5498 bool Function::TypeTest(TypeTestKind test_kind, 5357 bool Function::TypeTest(TypeTestKind test_kind,
5499 const AbstractTypeArguments& type_arguments, 5358 const TypeArguments& type_arguments,
5500 const Function& other, 5359 const Function& other,
5501 const AbstractTypeArguments& other_type_arguments, 5360 const TypeArguments& other_type_arguments,
5502 Error* bound_error) const { 5361 Error* bound_error) const {
5503 const intptr_t num_fixed_params = num_fixed_parameters(); 5362 const intptr_t num_fixed_params = num_fixed_parameters();
5504 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); 5363 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters();
5505 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); 5364 const intptr_t num_opt_named_params = NumOptionalNamedParameters();
5506 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); 5365 const intptr_t other_num_fixed_params = other.num_fixed_parameters();
5507 const intptr_t other_num_opt_pos_params = 5366 const intptr_t other_num_opt_pos_params =
5508 other.NumOptionalPositionalParameters(); 5367 other.NumOptionalPositionalParameters();
5509 const intptr_t other_num_opt_named_params = 5368 const intptr_t other_num_opt_named_params =
5510 other.NumOptionalNamedParameters(); 5369 other.NumOptionalNamedParameters();
5511 // This function requires the same arguments or less and accepts the same 5370 // This function requires the same arguments or less and accepts the same
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
5802 const TypeArguments& instantiator = TypeArguments::Handle(); 5661 const TypeArguments& instantiator = TypeArguments::Handle();
5803 BuildSignatureParameters(false, kUserVisibleName, instantiator, pieces); 5662 BuildSignatureParameters(false, kUserVisibleName, instantiator, pieces);
5804 const Array& strings = Array::Handle(Array::MakeArray(pieces)); 5663 const Array& strings = Array::Handle(Array::MakeArray(pieces));
5805 return String::ConcatAll(strings); 5664 return String::ConcatAll(strings);
5806 } 5665 }
5807 5666
5808 5667
5809 void Function::BuildSignatureParameters( 5668 void Function::BuildSignatureParameters(
5810 bool instantiate, 5669 bool instantiate,
5811 NameVisibility name_visibility, 5670 NameVisibility name_visibility,
5812 const AbstractTypeArguments& instantiator, 5671 const TypeArguments& instantiator,
5813 const GrowableObjectArray& pieces) const { 5672 const GrowableObjectArray& pieces) const {
5814 AbstractType& param_type = AbstractType::Handle(); 5673 AbstractType& param_type = AbstractType::Handle();
5815 const intptr_t num_params = NumParameters(); 5674 const intptr_t num_params = NumParameters();
5816 const intptr_t num_fixed_params = num_fixed_parameters(); 5675 const intptr_t num_fixed_params = num_fixed_parameters();
5817 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); 5676 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters();
5818 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); 5677 const intptr_t num_opt_named_params = NumOptionalNamedParameters();
5819 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; 5678 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params;
5820 ASSERT((num_fixed_params + num_opt_params) == num_params); 5679 ASSERT((num_fixed_params + num_opt_params) == num_params);
5821 String& name = String::Handle(); 5680 String& name = String::Handle();
5822 intptr_t i = 0; 5681 intptr_t i = 0;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
5876 ObjectStore* object_store = Isolate::Current()->object_store(); 5735 ObjectStore* object_store = Isolate::Current()->object_store();
5877 const Context& context = Context::Handle(object_store->empty_context()); 5736 const Context& context = Context::Handle(object_store->empty_context());
5878 const Instance& closure = 5737 const Instance& closure =
5879 Instance::Handle(Closure::New(*this, context, Heap::kOld)); 5738 Instance::Handle(Closure::New(*this, context, Heap::kOld));
5880 set_implicit_static_closure(closure); 5739 set_implicit_static_closure(closure);
5881 } 5740 }
5882 return implicit_static_closure(); 5741 return implicit_static_closure();
5883 } 5742 }
5884 5743
5885 5744
5886 RawString* Function::BuildSignature( 5745 RawString* Function::BuildSignature(bool instantiate,
5887 bool instantiate, 5746 NameVisibility name_visibility,
5888 NameVisibility name_visibility, 5747 const TypeArguments& instantiator) const {
5889 const AbstractTypeArguments& instantiator) const {
5890 const GrowableObjectArray& pieces = 5748 const GrowableObjectArray& pieces =
5891 GrowableObjectArray::Handle(GrowableObjectArray::New()); 5749 GrowableObjectArray::Handle(GrowableObjectArray::New());
5892 String& name = String::Handle(); 5750 String& name = String::Handle();
5893 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { 5751 if (!instantiate && !is_static() && (name_visibility == kInternalName)) {
5894 // Prefix the signature with its signature class and type parameters, if any 5752 // Prefix the signature with its signature class and type parameters, if any
5895 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the 5753 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the
5896 // signature class name is the alias name. 5754 // signature class name is the alias name.
5897 // The signature of static functions cannot be type parameterized. 5755 // The signature of static functions cannot be type parameterized.
5898 const Class& function_class = Class::Handle(Owner()); 5756 const Class& function_class = Class::Handle(Owner());
5899 ASSERT(!function_class.IsNull()); 5757 ASSERT(!function_class.IsNull());
(...skipping 5430 matching lines...) Expand 10 before | Expand all | Expand 10 after
11330 11188
11331 11189
11332 intptr_t SubtypeTestCache::NumberOfChecks() const { 11190 intptr_t SubtypeTestCache::NumberOfChecks() const {
11333 // Do not count the sentinel; 11191 // Do not count the sentinel;
11334 return (Array::Handle(cache()).Length() / kTestEntryLength) - 1; 11192 return (Array::Handle(cache()).Length() / kTestEntryLength) - 1;
11335 } 11193 }
11336 11194
11337 11195
11338 void SubtypeTestCache::AddCheck( 11196 void SubtypeTestCache::AddCheck(
11339 intptr_t instance_class_id, 11197 intptr_t instance_class_id,
11340 const AbstractTypeArguments& instance_type_arguments, 11198 const TypeArguments& instance_type_arguments,
11341 const AbstractTypeArguments& instantiator_type_arguments, 11199 const TypeArguments& instantiator_type_arguments,
11342 const Bool& test_result) const { 11200 const Bool& test_result) const {
11343 intptr_t old_num = NumberOfChecks(); 11201 intptr_t old_num = NumberOfChecks();
11344 Array& data = Array::Handle(cache()); 11202 Array& data = Array::Handle(cache());
11345 intptr_t new_len = data.Length() + kTestEntryLength; 11203 intptr_t new_len = data.Length() + kTestEntryLength;
11346 data = Array::Grow(data, new_len); 11204 data = Array::Grow(data, new_len);
11347 set_cache(data); 11205 set_cache(data);
11348 intptr_t data_pos = old_num * kTestEntryLength; 11206 intptr_t data_pos = old_num * kTestEntryLength;
11349 data.SetAt(data_pos + kInstanceClassId, 11207 data.SetAt(data_pos + kInstanceClassId,
11350 Smi::Handle(Smi::New(instance_class_id))); 11208 Smi::Handle(Smi::New(instance_class_id)));
11351 data.SetAt(data_pos + kInstanceTypeArguments, instance_type_arguments); 11209 data.SetAt(data_pos + kInstanceTypeArguments, instance_type_arguments);
11352 data.SetAt(data_pos + kInstantiatorTypeArguments, 11210 data.SetAt(data_pos + kInstantiatorTypeArguments,
11353 instantiator_type_arguments); 11211 instantiator_type_arguments);
11354 data.SetAt(data_pos + kTestResult, test_result); 11212 data.SetAt(data_pos + kTestResult, test_result);
11355 } 11213 }
11356 11214
11357 11215
11358 void SubtypeTestCache::GetCheck( 11216 void SubtypeTestCache::GetCheck(intptr_t ix,
11359 intptr_t ix, 11217 intptr_t* instance_class_id,
11360 intptr_t* instance_class_id, 11218 TypeArguments* instance_type_arguments,
11361 AbstractTypeArguments* instance_type_arguments, 11219 TypeArguments* instantiator_type_arguments,
11362 AbstractTypeArguments* instantiator_type_arguments, 11220 Bool* test_result) const {
11363 Bool* test_result) const {
11364 Array& data = Array::Handle(cache()); 11221 Array& data = Array::Handle(cache());
11365 intptr_t data_pos = ix * kTestEntryLength; 11222 intptr_t data_pos = ix * kTestEntryLength;
11366 *instance_class_id = 11223 *instance_class_id =
11367 Smi::Value(Smi::RawCast(data.At(data_pos + kInstanceClassId))); 11224 Smi::Value(Smi::RawCast(data.At(data_pos + kInstanceClassId)));
11368 *instance_type_arguments ^= data.At(data_pos + kInstanceTypeArguments); 11225 *instance_type_arguments ^= data.At(data_pos + kInstanceTypeArguments);
11369 *instantiator_type_arguments ^= 11226 *instantiator_type_arguments ^=
11370 data.At(data_pos + kInstantiatorTypeArguments); 11227 data.At(data_pos + kInstantiatorTypeArguments);
11371 *test_result ^= data.At(data_pos + kTestResult); 11228 *test_result ^= data.At(data_pos + kTestResult);
11372 } 11229 }
11373 11230
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
11908 } 11765 }
11909 11766
11910 11767
11911 RawType* Instance::GetType() const { 11768 RawType* Instance::GetType() const {
11912 if (IsNull()) { 11769 if (IsNull()) {
11913 return Type::NullType(); 11770 return Type::NullType();
11914 } 11771 }
11915 const Class& cls = Class::Handle(clazz()); 11772 const Class& cls = Class::Handle(clazz());
11916 Type& type = Type::Handle(cls.CanonicalType()); 11773 Type& type = Type::Handle(cls.CanonicalType());
11917 if (type.IsNull()) { 11774 if (type.IsNull()) {
11918 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); 11775 TypeArguments& type_arguments = TypeArguments::Handle();
11919 if (cls.NumTypeArguments() > 0) { 11776 if (cls.NumTypeArguments() > 0) {
11920 type_arguments = GetTypeArguments(); 11777 type_arguments = GetTypeArguments();
11921 } 11778 }
11922 type = Type::New(cls, type_arguments, Scanner::kNoSourcePos); 11779 type = Type::New(cls, type_arguments, Scanner::kNoSourcePos);
11923 type.SetIsFinalized(); 11780 type.SetIsFinalized();
11924 type ^= type.Canonicalize(); 11781 type ^= type.Canonicalize();
11925 } 11782 }
11926 return type.raw(); 11783 return type.raw();
11927 } 11784 }
11928 11785
11929 11786
11930 RawAbstractTypeArguments* Instance::GetTypeArguments() const { 11787 RawTypeArguments* Instance::GetTypeArguments() const {
11931 const Class& cls = Class::Handle(clazz()); 11788 const Class& cls = Class::Handle(clazz());
11932 intptr_t field_offset = cls.type_arguments_field_offset(); 11789 intptr_t field_offset = cls.type_arguments_field_offset();
11933 ASSERT(field_offset != Class::kNoTypeArguments); 11790 ASSERT(field_offset != Class::kNoTypeArguments);
11934 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); 11791 TypeArguments& type_arguments = TypeArguments::Handle();
11935 type_arguments ^= *FieldAddrAtOffset(field_offset); 11792 type_arguments ^= *FieldAddrAtOffset(field_offset);
11936 return type_arguments.raw(); 11793 return type_arguments.raw();
11937 } 11794 }
11938 11795
11939 11796
11940 void Instance::SetTypeArguments(const AbstractTypeArguments& value) const { 11797 void Instance::SetTypeArguments(const TypeArguments& value) const {
11798 ASSERT(value.IsNull() || value.IsCanonical());
11941 const Class& cls = Class::Handle(clazz()); 11799 const Class& cls = Class::Handle(clazz());
11942 intptr_t field_offset = cls.type_arguments_field_offset(); 11800 intptr_t field_offset = cls.type_arguments_field_offset();
11943 ASSERT(field_offset != Class::kNoTypeArguments); 11801 ASSERT(field_offset != Class::kNoTypeArguments);
11944 SetFieldAtOffset(field_offset, value); 11802 SetFieldAtOffset(field_offset, value);
11945 } 11803 }
11946 11804
11947 11805
11948 bool Instance::IsInstanceOf(const AbstractType& other, 11806 bool Instance::IsInstanceOf(const AbstractType& other,
11949 const AbstractTypeArguments& other_instantiator, 11807 const TypeArguments& other_instantiator,
11950 Error* bound_error) const { 11808 Error* bound_error) const {
11951 ASSERT(other.IsFinalized()); 11809 ASSERT(other.IsFinalized());
11952 ASSERT(!other.IsDynamicType()); 11810 ASSERT(!other.IsDynamicType());
11953 ASSERT(!other.IsMalformed()); 11811 ASSERT(!other.IsMalformed());
11954 ASSERT(!other.IsMalbounded()); 11812 ASSERT(!other.IsMalbounded());
11955 if (other.IsVoidType()) { 11813 if (other.IsVoidType()) {
11956 return false; 11814 return false;
11957 } 11815 }
11958 Isolate* isolate = Isolate::Current(); 11816 Isolate* isolate = Isolate::Current();
11959 const Class& cls = Class::Handle(isolate, clazz()); 11817 const Class& cls = Class::Handle(isolate, clazz());
11960 AbstractTypeArguments& type_arguments = 11818 TypeArguments& type_arguments =
11961 AbstractTypeArguments::Handle(isolate); 11819 TypeArguments::Handle(isolate);
11962 if (cls.NumTypeArguments() > 0) { 11820 if (cls.NumTypeArguments() > 0) {
11963 type_arguments = GetTypeArguments(); 11821 type_arguments = GetTypeArguments();
11964 if (!type_arguments.IsNull() && !type_arguments.IsCanonical()) { 11822 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical());
11965 type_arguments = type_arguments.Canonicalize();
11966 SetTypeArguments(type_arguments);
11967 }
11968 // The number of type arguments in the instance must be greater or equal to 11823 // The number of type arguments in the instance must be greater or equal to
11969 // the number of type arguments expected by the instance class. 11824 // the number of type arguments expected by the instance class.
11970 // A discrepancy is allowed for closures, which borrow the type argument 11825 // A discrepancy is allowed for closures, which borrow the type argument
11971 // vector of their instantiator, which may be of a subclass of the class 11826 // vector of their instantiator, which may be of a subclass of the class
11972 // defining the closure. Truncating the vector to the correct length on 11827 // defining the closure. Truncating the vector to the correct length on
11973 // instantiation is unnecessary. The vector may therefore be longer. 11828 // instantiation is unnecessary. The vector may therefore be longer.
11974 // Also, an optimization reuses the type argument vector of the instantiator 11829 // Also, an optimization reuses the type argument vector of the instantiator
11975 // of generic instances when its layout is compatible. 11830 // of generic instances when its layout is compatible.
11976 ASSERT(type_arguments.IsNull() || 11831 ASSERT(type_arguments.IsNull() ||
11977 (type_arguments.Length() >= cls.NumTypeArguments())); 11832 (type_arguments.Length() >= cls.NumTypeArguments()));
11978 } 11833 }
11979 Class& other_class = Class::Handle(isolate); 11834 Class& other_class = Class::Handle(isolate);
11980 AbstractTypeArguments& other_type_arguments = 11835 TypeArguments& other_type_arguments = TypeArguments::Handle(isolate);
11981 AbstractTypeArguments::Handle(isolate);
11982 // Note that we may encounter a bound error in checked mode. 11836 // Note that we may encounter a bound error in checked mode.
11983 if (!other.IsInstantiated()) { 11837 if (!other.IsInstantiated()) {
11984 const AbstractType& instantiated_other = AbstractType::Handle( 11838 const AbstractType& instantiated_other = AbstractType::Handle(
11985 isolate, other.InstantiateFrom(other_instantiator, bound_error)); 11839 isolate, other.InstantiateFrom(other_instantiator, bound_error));
11986 if ((bound_error != NULL) && !bound_error->IsNull()) { 11840 if ((bound_error != NULL) && !bound_error->IsNull()) {
11987 ASSERT(FLAG_enable_type_checks); 11841 ASSERT(FLAG_enable_type_checks);
11988 return false; 11842 return false;
11989 } 11843 }
11990 other_class = instantiated_other.type_class(); 11844 other_class = instantiated_other.type_class();
11991 other_type_arguments = instantiated_other.arguments(); 11845 other_type_arguments = instantiated_other.arguments();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
12098 return "non_constant"; 11952 return "non_constant";
12099 } else if (Isolate::Current()->no_gc_scope_depth() > 0) { 11953 } else if (Isolate::Current()->no_gc_scope_depth() > 0) {
12100 // Can occur when running disassembler. 11954 // Can occur when running disassembler.
12101 return "Instance"; 11955 return "Instance";
12102 } else { 11956 } else {
12103 if (IsClosure()) { 11957 if (IsClosure()) {
12104 return Closure::ToCString(*this); 11958 return Closure::ToCString(*this);
12105 } 11959 }
12106 const char* kFormat = "Instance of '%s'"; 11960 const char* kFormat = "Instance of '%s'";
12107 const Class& cls = Class::Handle(clazz()); 11961 const Class& cls = Class::Handle(clazz());
12108 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); 11962 TypeArguments& type_arguments = TypeArguments::Handle();
12109 const intptr_t num_type_arguments = cls.NumTypeArguments(); 11963 const intptr_t num_type_arguments = cls.NumTypeArguments();
12110 if (num_type_arguments > 0) { 11964 if (num_type_arguments > 0) {
12111 type_arguments = GetTypeArguments(); 11965 type_arguments = GetTypeArguments();
12112 } 11966 }
12113 const Type& type = 11967 const Type& type =
12114 Type::Handle(Type::New(cls, type_arguments, Scanner::kNoSourcePos)); 11968 Type::Handle(Type::New(cls, type_arguments, Scanner::kNoSourcePos));
12115 const String& type_name = String::Handle(type.UserVisibleName()); 11969 const String& type_name = String::Handle(type.UserVisibleName());
12116 // Calculate the size of the string. 11970 // Calculate the size of the string.
12117 intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1; 11971 intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1;
12118 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 11972 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
12206 } 12060 }
12207 12061
12208 12062
12209 RawUnresolvedClass* AbstractType::unresolved_class() const { 12063 RawUnresolvedClass* AbstractType::unresolved_class() const {
12210 // AbstractType is an abstract class. 12064 // AbstractType is an abstract class.
12211 UNREACHABLE(); 12065 UNREACHABLE();
12212 return UnresolvedClass::null(); 12066 return UnresolvedClass::null();
12213 } 12067 }
12214 12068
12215 12069
12216 RawAbstractTypeArguments* AbstractType::arguments() const { 12070 RawTypeArguments* AbstractType::arguments() const {
12217 // AbstractType is an abstract class. 12071 // AbstractType is an abstract class.
12218 UNREACHABLE(); 12072 UNREACHABLE();
12219 return NULL; 12073 return NULL;
12220 } 12074 }
12221 12075
12222 12076
12223 intptr_t AbstractType::token_pos() const { 12077 intptr_t AbstractType::token_pos() const {
12224 // AbstractType is an abstract class. 12078 // AbstractType is an abstract class.
12225 UNREACHABLE(); 12079 UNREACHABLE();
12226 return -1; 12080 return -1;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
12284 12138
12285 bool AbstractType::IsEquivalent(const Instance& other, 12139 bool AbstractType::IsEquivalent(const Instance& other,
12286 GrowableObjectArray* trail) const { 12140 GrowableObjectArray* trail) const {
12287 // AbstractType is an abstract class. 12141 // AbstractType is an abstract class.
12288 UNREACHABLE(); 12142 UNREACHABLE();
12289 return false; 12143 return false;
12290 } 12144 }
12291 12145
12292 12146
12293 RawAbstractType* AbstractType::InstantiateFrom( 12147 RawAbstractType* AbstractType::InstantiateFrom(
12294 const AbstractTypeArguments& instantiator_type_arguments, 12148 const TypeArguments& instantiator_type_arguments,
12295 Error* bound_error, 12149 Error* bound_error,
12296 GrowableObjectArray* trail) const { 12150 GrowableObjectArray* trail) const {
12297 // AbstractType is an abstract class. 12151 // AbstractType is an abstract class.
12298 UNREACHABLE(); 12152 UNREACHABLE();
12299 return NULL; 12153 return NULL;
12300 } 12154 }
12301 12155
12302 12156
12303 RawAbstractType* AbstractType::CloneUnfinalized() const { 12157 RawAbstractType* AbstractType::CloneUnfinalized() const {
12304 // AbstractType is an abstract class. 12158 // AbstractType is an abstract class.
(...skipping 20 matching lines...) Expand all
12325 type_name = String::Concat(type_name, Symbols::SpaceExtendsSpace()); 12179 type_name = String::Concat(type_name, Symbols::SpaceExtendsSpace());
12326 // Build the bound name without causing divergence. 12180 // Build the bound name without causing divergence.
12327 const AbstractType& bound = AbstractType::Handle( 12181 const AbstractType& bound = AbstractType::Handle(
12328 BoundedType::Cast(*this).bound()); 12182 BoundedType::Cast(*this).bound());
12329 String& bound_name = String::Handle(); 12183 String& bound_name = String::Handle();
12330 if (bound.IsTypeParameter()) { 12184 if (bound.IsTypeParameter()) {
12331 bound_name = TypeParameter::Cast(bound).name(); 12185 bound_name = TypeParameter::Cast(bound).name();
12332 } else if (bound.IsType()) { 12186 } else if (bound.IsType()) {
12333 const Class& cls = Class::Handle(Type::Cast(bound).type_class()); 12187 const Class& cls = Class::Handle(Type::Cast(bound).type_class());
12334 bound_name = cls.Name(); 12188 bound_name = cls.Name();
12335 if (Type::Cast(bound).arguments() != AbstractTypeArguments::null()) { 12189 if (Type::Cast(bound).arguments() != TypeArguments::null()) {
12336 bound_name = String::Concat(bound_name, Symbols::OptimizedOut()); 12190 bound_name = String::Concat(bound_name, Symbols::OptimizedOut());
12337 } 12191 }
12338 } else { 12192 } else {
12339 bound_name = String::New(Symbols::OptimizedOut()); 12193 bound_name = String::New(Symbols::OptimizedOut());
12340 } 12194 }
12341 type_name = String::Concat(type_name, bound_name); 12195 type_name = String::Concat(type_name, bound_name);
12342 return Symbols::New(type_name); 12196 return Symbols::New(type_name);
12343 } 12197 }
12344 if (IsTypeParameter()) { 12198 if (IsTypeParameter()) {
12345 return TypeParameter::Cast(*this).name(); 12199 return TypeParameter::Cast(*this).name();
12346 } 12200 }
12347 // If the type is still being finalized, we may be reporting an error about 12201 // If the type is still being finalized, we may be reporting an error about
12348 // a malformed type, so proceed with caution. 12202 // a malformed type, so proceed with caution.
12349 const AbstractTypeArguments& args = 12203 const TypeArguments& args = TypeArguments::Handle(arguments());
12350 AbstractTypeArguments::Handle(arguments());
12351 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); 12204 const intptr_t num_args = args.IsNull() ? 0 : args.Length();
12352 String& class_name = String::Handle(); 12205 String& class_name = String::Handle();
12353 intptr_t first_type_param_index; 12206 intptr_t first_type_param_index;
12354 intptr_t num_type_params; // Number of type parameters to print. 12207 intptr_t num_type_params; // Number of type parameters to print.
12355 if (HasResolvedTypeClass()) { 12208 if (HasResolvedTypeClass()) {
12356 const Class& cls = Class::Handle(type_class()); 12209 const Class& cls = Class::Handle(type_class());
12357 num_type_params = cls.NumTypeParameters(); // Do not print the full vector. 12210 num_type_params = cls.NumTypeParameters(); // Do not print the full vector.
12358 if (name_visibility == kInternalName) { 12211 if (name_visibility == kInternalName) {
12359 class_name = cls.Name(); 12212 class_name = cls.Name();
12360 } else { 12213 } else {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
12549 if (bound.IsMoreSpecificThan(other, bound_error)) { 12402 if (bound.IsMoreSpecificThan(other, bound_error)) {
12550 return true; 12403 return true;
12551 } 12404 }
12552 return false; // TODO(regis): We should return "maybe after instantiation". 12405 return false; // TODO(regis): We should return "maybe after instantiation".
12553 } 12406 }
12554 if (other.IsTypeParameter()) { 12407 if (other.IsTypeParameter()) {
12555 return false; // TODO(regis): We should return "maybe after instantiation". 12408 return false; // TODO(regis): We should return "maybe after instantiation".
12556 } 12409 }
12557 const Class& cls = Class::Handle(type_class()); 12410 const Class& cls = Class::Handle(type_class());
12558 return cls.TypeTest(test_kind, 12411 return cls.TypeTest(test_kind,
12559 AbstractTypeArguments::Handle(arguments()), 12412 TypeArguments::Handle(arguments()),
12560 Class::Handle(other.type_class()), 12413 Class::Handle(other.type_class()),
12561 AbstractTypeArguments::Handle(other.arguments()), 12414 TypeArguments::Handle(other.arguments()),
12562 bound_error); 12415 bound_error);
12563 } 12416 }
12564 12417
12565 12418
12566 intptr_t AbstractType::Hash() const { 12419 intptr_t AbstractType::Hash() const {
12567 // AbstractType is an abstract class. 12420 // AbstractType is an abstract class.
12568 UNREACHABLE(); 12421 UNREACHABLE();
12569 return 0; 12422 return 0;
12570 } 12423 }
12571 12424
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
12742 } 12595 }
12743 12596
12744 12597
12745 bool Type::IsResolved() const { 12598 bool Type::IsResolved() const {
12746 if (IsFinalized()) { 12599 if (IsFinalized()) {
12747 return true; 12600 return true;
12748 } 12601 }
12749 if (!HasResolvedTypeClass()) { 12602 if (!HasResolvedTypeClass()) {
12750 return false; 12603 return false;
12751 } 12604 }
12752 const AbstractTypeArguments& args = 12605 const TypeArguments& args = TypeArguments::Handle(arguments());
12753 AbstractTypeArguments::Handle(arguments());
12754 return args.IsNull() || args.IsResolved(); 12606 return args.IsNull() || args.IsResolved();
12755 } 12607 }
12756 12608
12757 12609
12758 bool Type::HasResolvedTypeClass() const { 12610 bool Type::HasResolvedTypeClass() const {
12759 const Object& type_class = Object::Handle(raw_ptr()->type_class_); 12611 const Object& type_class = Object::Handle(raw_ptr()->type_class_);
12760 return !type_class.IsNull() && type_class.IsClass(); 12612 return !type_class.IsNull() && type_class.IsClass();
12761 } 12613 }
12762 12614
12763 12615
(...skipping 17 matching lines...) Expand all
12781 ASSERT(!unresolved_class.IsNull()); 12633 ASSERT(!unresolved_class.IsNull());
12782 return unresolved_class.raw(); 12634 return unresolved_class.raw();
12783 #else 12635 #else
12784 ASSERT(!Object::Handle(raw_ptr()->type_class_).IsNull()); 12636 ASSERT(!Object::Handle(raw_ptr()->type_class_).IsNull());
12785 ASSERT(Object::Handle(raw_ptr()->type_class_).IsUnresolvedClass()); 12637 ASSERT(Object::Handle(raw_ptr()->type_class_).IsUnresolvedClass());
12786 return reinterpret_cast<RawUnresolvedClass*>(raw_ptr()->type_class_); 12638 return reinterpret_cast<RawUnresolvedClass*>(raw_ptr()->type_class_);
12787 #endif 12639 #endif
12788 } 12640 }
12789 12641
12790 12642
12791 RawAbstractTypeArguments* Type::arguments() const { 12643 RawTypeArguments* Type::arguments() const {
12792 return raw_ptr()->arguments_; 12644 return raw_ptr()->arguments_;
12793 } 12645 }
12794 12646
12795 12647
12796 bool Type::IsInstantiated(GrowableObjectArray* trail) const { 12648 bool Type::IsInstantiated(GrowableObjectArray* trail) const {
12797 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) { 12649 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) {
12798 return true; 12650 return true;
12799 } 12651 }
12800 if (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated) { 12652 if (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated) {
12801 return false; 12653 return false;
12802 } 12654 }
12803 const AbstractTypeArguments& args = 12655 const TypeArguments& args = TypeArguments::Handle(arguments());
12804 AbstractTypeArguments::Handle(arguments());
12805 return args.IsNull() || args.IsInstantiated(trail); 12656 return args.IsNull() || args.IsInstantiated(trail);
12806 } 12657 }
12807 12658
12808 12659
12809 RawAbstractType* Type::InstantiateFrom( 12660 RawAbstractType* Type::InstantiateFrom(
12810 const AbstractTypeArguments& instantiator_type_arguments, 12661 const TypeArguments& instantiator_type_arguments,
12811 Error* bound_error, 12662 Error* bound_error,
12812 GrowableObjectArray* trail) const { 12663 GrowableObjectArray* trail) const {
12813 ASSERT(IsFinalized() || IsBeingFinalized()); 12664 ASSERT(IsFinalized() || IsBeingFinalized());
12814 ASSERT(!IsInstantiated()); 12665 ASSERT(!IsInstantiated());
12815 // Return the uninstantiated type unchanged if malformed. No copy needed. 12666 // Return the uninstantiated type unchanged if malformed. No copy needed.
12816 if (IsMalformed()) { 12667 if (IsMalformed()) {
12817 return raw(); 12668 return raw();
12818 } 12669 }
12819 AbstractTypeArguments& type_arguments = 12670 TypeArguments& type_arguments = TypeArguments::Handle(arguments());
12820 AbstractTypeArguments::Handle(arguments());
12821 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, 12671 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments,
12822 bound_error, 12672 bound_error,
12823 trail); 12673 trail);
12824 // Note that the type class has to be resolved at this time, but not 12674 // Note that the type class has to be resolved at this time, but not
12825 // necessarily finalized yet. We may be checking bounds at compile time. 12675 // necessarily finalized yet. We may be checking bounds at compile time.
12826 const Class& cls = Class::Handle(type_class()); 12676 const Class& cls = Class::Handle(type_class());
12827 // This uninstantiated type is not modified, as it can be instantiated 12677 // This uninstantiated type is not modified, as it can be instantiated
12828 // with different instantiators. 12678 // with different instantiators.
12829 Type& instantiated_type = Type::Handle( 12679 Type& instantiated_type = Type::Handle(
12830 Type::New(cls, type_arguments, token_pos())); 12680 Type::New(cls, type_arguments, token_pos()));
12831 ASSERT(type_arguments.IsNull() || 12681 ASSERT(type_arguments.IsNull() ||
12832 (type_arguments.Length() == cls.NumTypeArguments())); 12682 (type_arguments.Length() == cls.NumTypeArguments()));
12833 instantiated_type.SetIsFinalized(); 12683 instantiated_type.SetIsFinalized();
12684 // Canonicalization is not part of instantiation.
12834 return instantiated_type.raw(); 12685 return instantiated_type.raw();
12835 } 12686 }
12836 12687
12837 12688
12838 bool Type::IsEquivalent(const Instance& other, 12689 bool Type::IsEquivalent(const Instance& other,
12839 GrowableObjectArray* trail) const { 12690 GrowableObjectArray* trail) const {
12840 ASSERT(!IsNull()); 12691 ASSERT(!IsNull());
12841 if (raw() == other.raw()) { 12692 if (raw() == other.raw()) {
12842 return true; 12693 return true;
12843 } 12694 }
(...skipping 22 matching lines...) Expand all
12866 return true; 12717 return true;
12867 } 12718 }
12868 const Class& cls = Class::Handle(type_class()); 12719 const Class& cls = Class::Handle(type_class());
12869 const intptr_t num_type_params = cls.NumTypeParameters(); 12720 const intptr_t num_type_params = cls.NumTypeParameters();
12870 if (num_type_params == 0) { 12721 if (num_type_params == 0) {
12871 // Shortcut unnecessary handle allocation below. 12722 // Shortcut unnecessary handle allocation below.
12872 return true; 12723 return true;
12873 } 12724 }
12874 const intptr_t num_type_args = cls.NumTypeArguments(); 12725 const intptr_t num_type_args = cls.NumTypeArguments();
12875 const intptr_t from_index = num_type_args - num_type_params; 12726 const intptr_t from_index = num_type_args - num_type_params;
12876 const AbstractTypeArguments& type_args = AbstractTypeArguments::Handle( 12727 const TypeArguments& type_args = TypeArguments::Handle(arguments());
12877 arguments()); 12728 const TypeArguments& other_type_args = TypeArguments::Handle(
12878 const AbstractTypeArguments& other_type_args = AbstractTypeArguments::Handle(
12879 other_type.arguments()); 12729 other_type.arguments());
12880 if (type_args.IsNull()) { 12730 if (type_args.IsNull()) {
12881 return other_type_args.IsRaw(from_index, num_type_params); 12731 return other_type_args.IsRaw(from_index, num_type_params);
12882 } 12732 }
12883 if (other_type_args.IsNull()) { 12733 if (other_type_args.IsNull()) {
12884 return type_args.IsRaw(from_index, num_type_params); 12734 return type_args.IsRaw(from_index, num_type_params);
12885 } 12735 }
12886 ASSERT(type_args.Length() >= (from_index + num_type_params)); 12736 ASSERT(type_args.Length() >= (from_index + num_type_params));
12887 ASSERT(other_type_args.Length() >= (from_index + num_type_params)); 12737 ASSERT(other_type_args.Length() >= (from_index + num_type_params));
12888 AbstractType& type_arg = AbstractType::Handle(); 12738 AbstractType& type_arg = AbstractType::Handle();
12889 AbstractType& other_type_arg = AbstractType::Handle(); 12739 AbstractType& other_type_arg = AbstractType::Handle();
12890 for (intptr_t i = 0; i < num_type_params; i++) { 12740 for (intptr_t i = 0; i < num_type_params; i++) {
12891 type_arg = type_args.TypeAt(from_index + i); 12741 type_arg = type_args.TypeAt(from_index + i);
12892 other_type_arg = other_type_args.TypeAt(from_index + i); 12742 other_type_arg = other_type_args.TypeAt(from_index + i);
12893 if (!type_arg.IsEquivalent(other_type_arg, trail)) { 12743 if (!type_arg.IsEquivalent(other_type_arg, trail)) {
12894 return false; 12744 return false;
12895 } 12745 }
12896 } 12746 }
12897 return true; 12747 return true;
12898 } 12748 }
12899 12749
12900 12750
12901 RawAbstractType* Type::CloneUnfinalized() const { 12751 RawAbstractType* Type::CloneUnfinalized() const {
12902 ASSERT(IsResolved()); 12752 ASSERT(IsResolved());
12903 if (IsFinalized()) { 12753 if (IsFinalized()) {
12904 return raw(); 12754 return raw();
12905 } 12755 }
12906 ASSERT(!IsMalformed()); // Malformed types are finalized. 12756 ASSERT(!IsMalformed()); // Malformed types are finalized.
12907 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. 12757 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization.
12908 AbstractTypeArguments& type_args = AbstractTypeArguments::Handle(arguments()); 12758 TypeArguments& type_args = TypeArguments::Handle(arguments());
12909 type_args = type_args.CloneUnfinalized(); 12759 type_args = type_args.CloneUnfinalized();
12910 const Class& type_cls = Class::Handle(type_class()); 12760 const Class& type_cls = Class::Handle(type_class());
12911 return Type::New(type_cls, type_args, token_pos()); 12761 return Type::New(type_cls, type_args, token_pos());
12912 } 12762 }
12913 12763
12914 12764
12915 RawAbstractType* Type::Canonicalize(GrowableObjectArray* trail) const { 12765 RawAbstractType* Type::Canonicalize(GrowableObjectArray* trail) const {
12916 ASSERT(IsFinalized()); 12766 ASSERT(IsFinalized());
12917 if (IsCanonical() || IsMalformed()) { 12767 if (IsCanonical() || IsMalformed()) {
12918 ASSERT(IsMalformed() || AbstractTypeArguments::Handle(arguments()).IsOld()); 12768 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld());
12919 return this->raw(); 12769 return this->raw();
12920 } 12770 }
12921 Isolate* isolate = Isolate::Current(); 12771 Isolate* isolate = Isolate::Current();
12922 Type& type = Type::Handle(isolate); 12772 Type& type = Type::Handle(isolate);
12923 const Class& cls = Class::Handle(isolate, type_class()); 12773 const Class& cls = Class::Handle(isolate, type_class());
12924 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) { 12774 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) {
12925 return Object::dynamic_type(); 12775 return Object::dynamic_type();
12926 } 12776 }
12927 // Fast canonical lookup/registry for simple types. 12777 // Fast canonical lookup/registry for simple types.
12928 if ((cls.NumTypeArguments() == 0) && !cls.IsSignatureClass()) { 12778 if ((cls.NumTypeArguments() == 0) && !cls.IsSignatureClass()) {
(...skipping 24 matching lines...) Expand all
12953 if (type.IsNull()) { 12803 if (type.IsNull()) {
12954 break; 12804 break;
12955 } 12805 }
12956 ASSERT(type.IsFinalized()); 12806 ASSERT(type.IsFinalized());
12957 if (this->Equals(type)) { 12807 if (this->Equals(type)) {
12958 return type.raw(); 12808 return type.raw();
12959 } 12809 }
12960 index++; 12810 index++;
12961 } 12811 }
12962 // Canonicalize the type arguments. 12812 // Canonicalize the type arguments.
12963 AbstractTypeArguments& type_args = 12813 TypeArguments& type_args = TypeArguments::Handle(isolate, arguments());
12964 AbstractTypeArguments::Handle(isolate, arguments());
12965 // In case the type is first canonicalized at runtime, its type argument 12814 // In case the type is first canonicalized at runtime, its type argument
12966 // vector may be longer than necessary. This is not an issue. 12815 // vector may be longer than necessary. This is not an issue.
12967 ASSERT(type_args.IsNull() || (type_args.Length() >= cls.NumTypeArguments())); 12816 ASSERT(type_args.IsNull() || (type_args.Length() >= cls.NumTypeArguments()));
12968 type_args = type_args.Canonicalize(trail); 12817 type_args = type_args.Canonicalize(trail);
12969 set_arguments(type_args); 12818 set_arguments(type_args);
12970 // The type needs to be added to the list. Grow the list if it is full. 12819 // The type needs to be added to the list. Grow the list if it is full.
12971 if (index == canonical_types_len) { 12820 if (index == canonical_types_len) {
12972 const intptr_t kLengthIncrement = 2; // Raw and parameterized. 12821 const intptr_t kLengthIncrement = 2; // Raw and parameterized.
12973 const intptr_t new_length = canonical_types.Length() + kLengthIncrement; 12822 const intptr_t new_length = canonical_types.Length() + kLengthIncrement;
12974 const Array& new_canonical_types = Array::Handle( 12823 const Array& new_canonical_types = Array::Handle(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
13007 SetCanonical(); 12856 SetCanonical();
13008 return this->raw(); 12857 return this->raw();
13009 } 12858 }
13010 12859
13011 12860
13012 intptr_t Type::Hash() const { 12861 intptr_t Type::Hash() const {
13013 ASSERT(IsFinalized()); 12862 ASSERT(IsFinalized());
13014 uword result = 1; 12863 uword result = 1;
13015 if (IsMalformed()) return result; 12864 if (IsMalformed()) return result;
13016 result += Class::Handle(type_class()).id(); 12865 result += Class::Handle(type_class()).id();
13017 result += AbstractTypeArguments::Handle(arguments()).Hash(); 12866 result += TypeArguments::Handle(arguments()).Hash();
13018 return FinalizeHash(result); 12867 return FinalizeHash(result);
13019 } 12868 }
13020 12869
13021 12870
13022 void Type::set_type_class(const Object& value) const { 12871 void Type::set_type_class(const Object& value) const {
13023 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass())); 12872 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass()));
13024 StorePointer(&raw_ptr()->type_class_, value.raw()); 12873 StorePointer(&raw_ptr()->type_class_, value.raw());
13025 } 12874 }
13026 12875
13027 12876
13028 void Type::set_arguments(const AbstractTypeArguments& value) const { 12877 void Type::set_arguments(const TypeArguments& value) const {
13029 StorePointer(&raw_ptr()->arguments_, value.raw()); 12878 StorePointer(&raw_ptr()->arguments_, value.raw());
13030 } 12879 }
13031 12880
13032 12881
13033 RawType* Type::New(Heap::Space space) { 12882 RawType* Type::New(Heap::Space space) {
13034 ASSERT(Isolate::Current()->object_store()->type_class() != Class::null()); 12883 ASSERT(Isolate::Current()->object_store()->type_class() != Class::null());
13035 RawObject* raw = Object::Allocate(Type::kClassId, 12884 RawObject* raw = Object::Allocate(Type::kClassId,
13036 Type::InstanceSize(), 12885 Type::InstanceSize(),
13037 space); 12886 space);
13038 return reinterpret_cast<RawType*>(raw); 12887 return reinterpret_cast<RawType*>(raw);
13039 } 12888 }
13040 12889
13041 12890
13042 RawType* Type::New(const Object& clazz, 12891 RawType* Type::New(const Object& clazz,
13043 const AbstractTypeArguments& arguments, 12892 const TypeArguments& arguments,
13044 intptr_t token_pos, 12893 intptr_t token_pos,
13045 Heap::Space space) { 12894 Heap::Space space) {
13046 const Type& result = Type::Handle(Type::New(space)); 12895 const Type& result = Type::Handle(Type::New(space));
13047 result.set_type_class(clazz); 12896 result.set_type_class(clazz);
13048 result.set_arguments(arguments); 12897 result.set_arguments(arguments);
13049 result.set_token_pos(token_pos); 12898 result.set_token_pos(token_pos);
13050 result.raw_ptr()->type_state_ = RawType::kAllocated; 12899 result.raw_ptr()->type_state_ = RawType::kAllocated;
13051 return result.raw(); 12900 return result.raw();
13052 } 12901 }
13053 12902
13054 12903
13055 void Type::set_token_pos(intptr_t token_pos) const { 12904 void Type::set_token_pos(intptr_t token_pos) const {
13056 ASSERT(token_pos >= 0); 12905 ASSERT(token_pos >= 0);
13057 raw_ptr()->token_pos_ = token_pos; 12906 raw_ptr()->token_pos_ = token_pos;
13058 } 12907 }
13059 12908
13060 12909
13061 void Type::set_type_state(int8_t state) const { 12910 void Type::set_type_state(int8_t state) const {
13062 ASSERT((state == RawType::kAllocated) || 12911 ASSERT((state == RawType::kAllocated) ||
13063 (state == RawType::kBeingFinalized) || 12912 (state == RawType::kBeingFinalized) ||
13064 (state == RawType::kFinalizedInstantiated) || 12913 (state == RawType::kFinalizedInstantiated) ||
13065 (state == RawType::kFinalizedUninstantiated)); 12914 (state == RawType::kFinalizedUninstantiated));
13066 raw_ptr()->type_state_ = state; 12915 raw_ptr()->type_state_ = state;
13067 } 12916 }
13068 12917
13069 12918
13070 const char* Type::ToCString() const { 12919 const char* Type::ToCString() const {
13071 if (IsResolved()) { 12920 if (IsResolved()) {
13072 const AbstractTypeArguments& type_arguments = 12921 const TypeArguments& type_arguments = TypeArguments::Handle(arguments());
13073 AbstractTypeArguments::Handle(arguments());
13074 const char* class_name; 12922 const char* class_name;
13075 if (HasResolvedTypeClass()) { 12923 if (HasResolvedTypeClass()) {
13076 class_name = String::Handle( 12924 class_name = String::Handle(
13077 Class::Handle(type_class()).Name()).ToCString(); 12925 Class::Handle(type_class()).Name()).ToCString();
13078 } else { 12926 } else {
13079 class_name = UnresolvedClass::Handle(unresolved_class()).ToCString(); 12927 class_name = UnresolvedClass::Handle(unresolved_class()).ToCString();
13080 } 12928 }
13081 if (type_arguments.IsNull()) { 12929 if (type_arguments.IsNull()) {
13082 const char* format = "Type: class '%s'"; 12930 const char* format = "Type: class '%s'";
13083 intptr_t len = OS::SNPrint(NULL, 0, format, class_name) + 1; 12931 intptr_t len = OS::SNPrint(NULL, 0, format, class_name) + 1;
13084 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 12932 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
13085 OS::SNPrint(chars, len, format, class_name); 12933 OS::SNPrint(chars, len, format, class_name);
13086 return chars; 12934 return chars;
13087 } else { 12935 } else {
13088 const char* format = "Type: class '%s', args:[%s]"; 12936 const char* format = "Type: class '%s', args:[%s]";
13089 const char* args_cstr = 12937 const char* args_cstr = TypeArguments::Handle(arguments()).ToCString();
13090 AbstractTypeArguments::Handle(arguments()).ToCString();
13091 intptr_t len = OS::SNPrint(NULL, 0, format, class_name, args_cstr) + 1; 12938 intptr_t len = OS::SNPrint(NULL, 0, format, class_name, args_cstr) + 1;
13092 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 12939 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
13093 OS::SNPrint(chars, len, format, class_name, args_cstr); 12940 OS::SNPrint(chars, len, format, class_name, args_cstr);
13094 return chars; 12941 return chars;
13095 } 12942 }
13096 } else { 12943 } else {
13097 return "Unresolved Type"; 12944 return "Unresolved Type";
13098 } 12945 }
13099 } 12946 }
13100 12947
(...skipping 17 matching lines...) Expand all
13118 return true; 12965 return true;
13119 } 12966 }
13120 if (TestAndAddBuddyToTrail(&trail, other)) { 12967 if (TestAndAddBuddyToTrail(&trail, other)) {
13121 return true; 12968 return true;
13122 } 12969 }
13123 return AbstractType::Handle(type()).IsEquivalent(other, trail); 12970 return AbstractType::Handle(type()).IsEquivalent(other, trail);
13124 } 12971 }
13125 12972
13126 12973
13127 RawAbstractType* TypeRef::InstantiateFrom( 12974 RawAbstractType* TypeRef::InstantiateFrom(
13128 const AbstractTypeArguments& instantiator_type_arguments, 12975 const TypeArguments& instantiator_type_arguments,
13129 Error* bound_error, 12976 Error* bound_error,
13130 GrowableObjectArray* trail) const { 12977 GrowableObjectArray* trail) const {
13131 TypeRef& instantiated_type_ref = TypeRef::Handle(); 12978 TypeRef& instantiated_type_ref = TypeRef::Handle();
13132 instantiated_type_ref ^= OnlyBuddyInTrail(trail); 12979 instantiated_type_ref ^= OnlyBuddyInTrail(trail);
13133 if (!instantiated_type_ref.IsNull()) { 12980 if (!instantiated_type_ref.IsNull()) {
13134 return instantiated_type_ref.raw(); 12981 return instantiated_type_ref.raw();
13135 } 12982 }
13136 instantiated_type_ref = TypeRef::New(Type::Handle(Type::DynamicType())); 12983 instantiated_type_ref = TypeRef::New(Type::Handle(Type::DynamicType()));
13137 AddOnlyBuddyToTrail(&trail, instantiated_type_ref); 12984 AddOnlyBuddyToTrail(&trail, instantiated_type_ref);
13138 const AbstractType& ref_type = AbstractType::Handle(type()); 12985 const AbstractType& ref_type = AbstractType::Handle(type());
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
13252 result.set_type(type); 13099 result.set_type(type);
13253 return result.raw(); 13100 return result.raw();
13254 } 13101 }
13255 13102
13256 13103
13257 const char* TypeRef::ToCString() const { 13104 const char* TypeRef::ToCString() const {
13258 const char* format = "TypeRef: %s%s"; 13105 const char* format = "TypeRef: %s%s";
13259 const char* type_cstr = String::Handle(Class::Handle(AbstractType::Handle( 13106 const char* type_cstr = String::Handle(Class::Handle(AbstractType::Handle(
13260 type()).type_class()).Name()).ToCString(); 13107 type()).type_class()).Name()).ToCString();
13261 const char* args_cstr = (AbstractType::Handle( 13108 const char* args_cstr = (AbstractType::Handle(
13262 type()).arguments() == AbstractTypeArguments::null()) ? "" : "<...>"; 13109 type()).arguments() == TypeArguments::null()) ? "" : "<...>";
13263 intptr_t len = OS::SNPrint(NULL, 0, format, type_cstr, args_cstr) + 1; 13110 intptr_t len = OS::SNPrint(NULL, 0, format, type_cstr, args_cstr) + 1;
13264 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 13111 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
13265 OS::SNPrint(chars, len, format, type_cstr, args_cstr); 13112 OS::SNPrint(chars, len, format, type_cstr, args_cstr);
13266 return chars; 13113 return chars;
13267 } 13114 }
13268 13115
13269 13116
13270 void TypeRef::PrintToJSONStream(JSONStream* stream, bool ref) const { 13117 void TypeRef::PrintToJSONStream(JSONStream* stream, bool ref) const {
13271 JSONObject jsobj(stream); 13118 JSONObject jsobj(stream);
13272 } 13119 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
13321 StorePointer(&raw_ptr()->name_, value.raw()); 13168 StorePointer(&raw_ptr()->name_, value.raw());
13322 } 13169 }
13323 13170
13324 13171
13325 void TypeParameter::set_bound(const AbstractType& value) const { 13172 void TypeParameter::set_bound(const AbstractType& value) const {
13326 StorePointer(&raw_ptr()->bound_, value.raw()); 13173 StorePointer(&raw_ptr()->bound_, value.raw());
13327 } 13174 }
13328 13175
13329 13176
13330 RawAbstractType* TypeParameter::InstantiateFrom( 13177 RawAbstractType* TypeParameter::InstantiateFrom(
13331 const AbstractTypeArguments& instantiator_type_arguments, 13178 const TypeArguments& instantiator_type_arguments,
13332 Error* bound_error, 13179 Error* bound_error,
13333 GrowableObjectArray* trail) const { 13180 GrowableObjectArray* trail) const {
13334 ASSERT(IsFinalized()); 13181 ASSERT(IsFinalized());
13335 if (instantiator_type_arguments.IsNull()) { 13182 if (instantiator_type_arguments.IsNull()) {
13336 return Type::DynamicType(); 13183 return Type::DynamicType();
13337 } 13184 }
13338 const AbstractType& type_arg = AbstractType::Handle( 13185 const AbstractType& type_arg = AbstractType::Handle(
13339 instantiator_type_arguments.TypeAt(index())); 13186 instantiator_type_arguments.TypeAt(index()));
13340 // There is no need to canonicalize the instantiated type parameter, since all 13187 // There is no need to canonicalize the instantiated type parameter, since all
13341 // type arguments are canonicalized at type finalization time. It would be too 13188 // type arguments are canonicalized at type finalization time. It would be too
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
13546 13393
13547 void BoundedType::set_type_parameter(const TypeParameter& value) const { 13394 void BoundedType::set_type_parameter(const TypeParameter& value) const {
13548 // A null type parameter is set when marking a type malformed because of a 13395 // A null type parameter is set when marking a type malformed because of a
13549 // bound error at compile time. 13396 // bound error at compile time.
13550 ASSERT(value.IsNull() || value.IsFinalized()); 13397 ASSERT(value.IsNull() || value.IsFinalized());
13551 StorePointer(&raw_ptr()->type_parameter_, value.raw()); 13398 StorePointer(&raw_ptr()->type_parameter_, value.raw());
13552 } 13399 }
13553 13400
13554 13401
13555 RawAbstractType* BoundedType::InstantiateFrom( 13402 RawAbstractType* BoundedType::InstantiateFrom(
13556 const AbstractTypeArguments& instantiator_type_arguments, 13403 const TypeArguments& instantiator_type_arguments,
13557 Error* bound_error, 13404 Error* bound_error,
13558 GrowableObjectArray* trail) const { 13405 GrowableObjectArray* trail) const {
13559 ASSERT(IsFinalized()); 13406 ASSERT(IsFinalized());
13560 AbstractType& bounded_type = AbstractType::Handle(type()); 13407 AbstractType& bounded_type = AbstractType::Handle(type());
13561 if (!bounded_type.IsInstantiated()) { 13408 if (!bounded_type.IsInstantiated()) {
13562 bounded_type = bounded_type.InstantiateFrom(instantiator_type_arguments, 13409 bounded_type = bounded_type.InstantiateFrom(instantiator_type_arguments,
13563 bound_error, 13410 bound_error,
13564 trail); 13411 trail);
13565 } 13412 }
13566 if (FLAG_enable_type_checks && bound_error->IsNull()) { 13413 if (FLAG_enable_type_checks && bound_error->IsNull()) {
(...skipping 2657 matching lines...) Expand 10 before | Expand all | Expand 10 after
16224 // Both handles point to the same raw instance. 16071 // Both handles point to the same raw instance.
16225 return true; 16072 return true;
16226 } 16073 }
16227 16074
16228 // An Array may be compared to an ImmutableArray. 16075 // An Array may be compared to an ImmutableArray.
16229 if (!other.IsArray() || other.IsNull()) { 16076 if (!other.IsArray() || other.IsNull()) {
16230 return false; 16077 return false;
16231 } 16078 }
16232 16079
16233 // Both arrays must have the same type arguments. 16080 // Both arrays must have the same type arguments.
16234 const AbstractTypeArguments& type_args = AbstractTypeArguments::Handle( 16081 const TypeArguments& type_args = TypeArguments::Handle(GetTypeArguments());
16235 GetTypeArguments()); 16082 const TypeArguments& other_type_args = TypeArguments::Handle(
16236 const AbstractTypeArguments& other_type_args = AbstractTypeArguments::Handle(
16237 other.GetTypeArguments()); 16083 other.GetTypeArguments());
16238 if (!type_args.Equals(other_type_args)) { 16084 if (!type_args.Equals(other_type_args)) {
16239 return false; 16085 return false;
16240 } 16086 }
16241 16087
16242 const Array& other_arr = Array::Cast(other); 16088 const Array& other_arr = Array::Cast(other);
16243 16089
16244 intptr_t len = this->Length(); 16090 intptr_t len = this->Length();
16245 if (len != other_arr.Length()) { 16091 if (len != other_arr.Length()) {
16246 return false; 16092 return false;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
16303 void Array::PrintToJSONStream(JSONStream* stream, bool ref) const { 16149 void Array::PrintToJSONStream(JSONStream* stream, bool ref) const {
16304 Instance::PrintToJSONStream(stream, ref); 16150 Instance::PrintToJSONStream(stream, ref);
16305 } 16151 }
16306 16152
16307 16153
16308 RawArray* Array::Grow(const Array& source, int new_length, Heap::Space space) { 16154 RawArray* Array::Grow(const Array& source, int new_length, Heap::Space space) {
16309 const Array& result = Array::Handle(Array::New(new_length, space)); 16155 const Array& result = Array::Handle(Array::New(new_length, space));
16310 intptr_t len = 0; 16156 intptr_t len = 0;
16311 if (!source.IsNull()) { 16157 if (!source.IsNull()) {
16312 len = source.Length(); 16158 len = source.Length();
16313 result.SetTypeArguments( 16159 result.SetTypeArguments(TypeArguments::Handle(source.GetTypeArguments()));
16314 AbstractTypeArguments::Handle(source.GetTypeArguments()));
16315 } 16160 }
16316 ASSERT(new_length >= len); // Cannot copy 'source' into new array. 16161 ASSERT(new_length >= len); // Cannot copy 'source' into new array.
16317 ASSERT(new_length != len); // Unnecessary copying of array. 16162 ASSERT(new_length != len); // Unnecessary copying of array.
16318 Object& obj = Object::Handle(); 16163 Object& obj = Object::Handle();
16319 for (int i = 0; i < len; i++) { 16164 for (int i = 0; i < len; i++) {
16320 obj = source.At(i); 16165 obj = source.At(i);
16321 result.SetAt(i, obj); 16166 result.SetAt(i, obj);
16322 } 16167 }
16323 return result.raw(); 16168 return result.raw();
16324 } 16169 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
16448 } 16293 }
16449 16294
16450 const GrowableObjectArray& other_arr = GrowableObjectArray::Cast(other); 16295 const GrowableObjectArray& other_arr = GrowableObjectArray::Cast(other);
16451 16296
16452 // The capacity and length of both objects must be equal. 16297 // The capacity and length of both objects must be equal.
16453 if (Capacity() != other_arr.Capacity() || Length() != other_arr.Length()) { 16298 if (Capacity() != other_arr.Capacity() || Length() != other_arr.Length()) {
16454 return false; 16299 return false;
16455 } 16300 }
16456 16301
16457 // Both arrays must have the same type arguments. 16302 // Both arrays must have the same type arguments.
16458 const AbstractTypeArguments& type_args = AbstractTypeArguments::Handle( 16303 const TypeArguments& type_args = TypeArguments::Handle(GetTypeArguments());
16459 GetTypeArguments()); 16304 const TypeArguments& other_type_args = TypeArguments::Handle(
16460 const AbstractTypeArguments& other_type_args = AbstractTypeArguments::Handle(
16461 other.GetTypeArguments()); 16305 other.GetTypeArguments());
16462 if (!type_args.Equals(other_type_args)) { 16306 if (!type_args.Equals(other_type_args)) {
16463 return false; 16307 return false;
16464 } 16308 }
16465 16309
16466 // The data part in both arrays must be identical. 16310 // The data part in both arrays must be identical.
16467 const Array& contents = Array::Handle(data()); 16311 const Array& contents = Array::Handle(data());
16468 const Array& other_contents = Array::Handle(other_arr.data()); 16312 const Array& other_contents = Array::Handle(other_arr.data());
16469 for (intptr_t i = 0; i < Length(); i++) { 16313 for (intptr_t i = 0; i < Length(); i++) {
16470 if (contents.At(i) != other_contents.At(i)) { 16314 if (contents.At(i) != other_contents.At(i)) {
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
17467 return "_MirrorReference"; 17311 return "_MirrorReference";
17468 } 17312 }
17469 17313
17470 17314
17471 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 17315 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
17472 Instance::PrintToJSONStream(stream, ref); 17316 Instance::PrintToJSONStream(stream, ref);
17473 } 17317 }
17474 17318
17475 17319
17476 } // namespace dart 17320 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | runtime/vm/stub_code_ia32.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698