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

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

Issue 1815733003: Remove recently introduced FunctionType vm class by merging it into class Type. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (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 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 // canonical_type_arguments_ are Smi terminated. 1143 // canonical_type_arguments_ are Smi terminated.
1144 // Last element contains the count of used slots. 1144 // Last element contains the count of used slots.
1145 const intptr_t kInitialCanonicalTypeArgumentsSize = 4; 1145 const intptr_t kInitialCanonicalTypeArgumentsSize = 4;
1146 array = Array::New(kInitialCanonicalTypeArgumentsSize + 1); 1146 array = Array::New(kInitialCanonicalTypeArgumentsSize + 1);
1147 array.SetAt(kInitialCanonicalTypeArgumentsSize, 1147 array.SetAt(kInitialCanonicalTypeArgumentsSize,
1148 Smi::Handle(zone, Smi::New(0))); 1148 Smi::Handle(zone, Smi::New(0)));
1149 object_store->set_canonical_type_arguments(array); 1149 object_store->set_canonical_type_arguments(array);
1150 1150
1151 // Setup type class early in the process. 1151 // Setup type class early in the process.
1152 const Class& type_cls = Class::Handle(zone, Class::New<Type>()); 1152 const Class& type_cls = Class::Handle(zone, Class::New<Type>());
1153 const Class& function_type_cls = Class::Handle(zone,
1154 Class::New<FunctionType>());
1155 const Class& type_ref_cls = Class::Handle(zone, Class::New<TypeRef>()); 1153 const Class& type_ref_cls = Class::Handle(zone, Class::New<TypeRef>());
1156 const Class& type_parameter_cls = Class::Handle(zone, 1154 const Class& type_parameter_cls = Class::Handle(zone,
1157 Class::New<TypeParameter>()); 1155 Class::New<TypeParameter>());
1158 const Class& bounded_type_cls = Class::Handle(zone, 1156 const Class& bounded_type_cls = Class::Handle(zone,
1159 Class::New<BoundedType>()); 1157 Class::New<BoundedType>());
1160 const Class& mixin_app_type_cls = Class::Handle(zone, 1158 const Class& mixin_app_type_cls = Class::Handle(zone,
1161 Class::New<MixinAppType>()); 1159 Class::New<MixinAppType>());
1162 const Class& library_prefix_cls = Class::Handle(zone, 1160 const Class& library_prefix_cls = Class::Handle(zone,
1163 Class::New<LibraryPrefix>()); 1161 Class::New<LibraryPrefix>());
1164 1162
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 RegisterClass(cls, Symbols::Null(), core_lib); 1305 RegisterClass(cls, Symbols::Null(), core_lib);
1308 pending_classes.Add(cls); 1306 pending_classes.Add(cls);
1309 1307
1310 ASSERT(!library_prefix_cls.IsNull()); 1308 ASSERT(!library_prefix_cls.IsNull());
1311 RegisterPrivateClass(library_prefix_cls, Symbols::_LibraryPrefix(), core_lib); 1309 RegisterPrivateClass(library_prefix_cls, Symbols::_LibraryPrefix(), core_lib);
1312 pending_classes.Add(library_prefix_cls); 1310 pending_classes.Add(library_prefix_cls);
1313 1311
1314 RegisterPrivateClass(type_cls, Symbols::Type(), core_lib); 1312 RegisterPrivateClass(type_cls, Symbols::Type(), core_lib);
1315 pending_classes.Add(type_cls); 1313 pending_classes.Add(type_cls);
1316 1314
1317 RegisterPrivateClass(function_type_cls, Symbols::FunctionType(), core_lib);
1318 pending_classes.Add(function_type_cls);
1319
1320 RegisterPrivateClass(type_ref_cls, Symbols::TypeRef(), core_lib); 1315 RegisterPrivateClass(type_ref_cls, Symbols::TypeRef(), core_lib);
1321 pending_classes.Add(type_ref_cls); 1316 pending_classes.Add(type_ref_cls);
1322 1317
1323 RegisterPrivateClass(type_parameter_cls, Symbols::TypeParameter(), core_lib); 1318 RegisterPrivateClass(type_parameter_cls, Symbols::TypeParameter(), core_lib);
1324 pending_classes.Add(type_parameter_cls); 1319 pending_classes.Add(type_parameter_cls);
1325 1320
1326 RegisterPrivateClass(bounded_type_cls, Symbols::BoundedType(), core_lib); 1321 RegisterPrivateClass(bounded_type_cls, Symbols::BoundedType(), core_lib);
1327 pending_classes.Add(bounded_type_cls); 1322 pending_classes.Add(bounded_type_cls);
1328 1323
1329 RegisterPrivateClass(mixin_app_type_cls, Symbols::MixinAppType(), core_lib); 1324 RegisterPrivateClass(mixin_app_type_cls, Symbols::MixinAppType(), core_lib);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 // This is done to allow bootstrapping of reading classes from the snapshot. 1628 // This is done to allow bootstrapping of reading classes from the snapshot.
1634 // Some classes are not stored in the object store. Yet we still need to 1629 // Some classes are not stored in the object store. Yet we still need to
1635 // create their Class object so that they get put into the class_table 1630 // create their Class object so that they get put into the class_table
1636 // (as a side effect of Class::New()). 1631 // (as a side effect of Class::New()).
1637 1632
1638 cls = Class::New<Instance>(kInstanceCid); 1633 cls = Class::New<Instance>(kInstanceCid);
1639 object_store->set_object_class(cls); 1634 object_store->set_object_class(cls);
1640 1635
1641 cls = Class::New<LibraryPrefix>(); 1636 cls = Class::New<LibraryPrefix>();
1642 cls = Class::New<Type>(); 1637 cls = Class::New<Type>();
1643 cls = Class::New<FunctionType>();
1644 cls = Class::New<TypeRef>(); 1638 cls = Class::New<TypeRef>();
1645 cls = Class::New<TypeParameter>(); 1639 cls = Class::New<TypeParameter>();
1646 cls = Class::New<BoundedType>(); 1640 cls = Class::New<BoundedType>();
1647 cls = Class::New<MixinAppType>(); 1641 cls = Class::New<MixinAppType>();
1648 1642
1649 cls = Class::New<Array>(); 1643 cls = Class::New<Array>();
1650 object_store->set_array_class(cls); 1644 object_store->set_array_class(cls);
1651 1645
1652 cls = Class::New<Array>(kImmutableArrayCid); 1646 cls = Class::New<Array>(kImmutableArrayCid);
1653 object_store->set_immutable_array_class(cls); 1647 object_store->set_immutable_array_class(cls);
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
2426 do { 2420 do {
2427 // Calling NumOwnTypeArguments() on a mixin application class will setup the 2421 // Calling NumOwnTypeArguments() on a mixin application class will setup the
2428 // type parameters if not already done. 2422 // type parameters if not already done.
2429 num_type_args += cls.NumOwnTypeArguments(); 2423 num_type_args += cls.NumOwnTypeArguments();
2430 // Super type of Object class is null. 2424 // Super type of Object class is null.
2431 if ((cls.super_type() == AbstractType::null()) || 2425 if ((cls.super_type() == AbstractType::null()) ||
2432 (cls.super_type() == isolate->object_store()->object_type())) { 2426 (cls.super_type() == isolate->object_store()->object_type())) {
2433 break; 2427 break;
2434 } 2428 }
2435 sup_type = cls.super_type(); 2429 sup_type = cls.super_type();
2436 // A BoundedType, TypeRef, or FunctionType can appear as type argument of 2430 // A BoundedType, TypeRef, or function type can appear as type argument of
2437 // sup_type, but not as sup_type itself. 2431 // sup_type, but not as sup_type itself.
2438 ASSERT(sup_type.IsType()); 2432 ASSERT(sup_type.IsType());
2439 sup_type = ClassFinalizer::ResolveTypeClass(cls, Type::Cast(sup_type)); 2433 ClassFinalizer::ResolveTypeClass(cls, Type::Cast(sup_type));
2440 cls = sup_type.type_class(); 2434 cls = sup_type.type_class();
2441 ASSERT(!cls.IsTypedefClass()); 2435 ASSERT(!cls.IsTypedefClass());
2442 } while (true); 2436 } while (true);
2443 set_num_type_arguments(num_type_args); 2437 set_num_type_arguments(num_type_args);
2444 return num_type_args; 2438 return num_type_args;
2445 } 2439 }
2446 2440
2447 2441
2448 RawClass* Class::SuperClass() const { 2442 RawClass* Class::SuperClass() const {
2449 if (super_type() == AbstractType::null()) { 2443 if (super_type() == AbstractType::null()) {
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after
3631 return; 3625 return;
3632 } 3626 }
3633 ASSERT(!existing_stub.IsDisabled()); 3627 ASSERT(!existing_stub.IsDisabled());
3634 // Change the stub so that the next caller will regenerate the stub. 3628 // Change the stub so that the next caller will regenerate the stub.
3635 existing_stub.DisableStubCode(); 3629 existing_stub.DisableStubCode();
3636 // Disassociate the existing stub from class. 3630 // Disassociate the existing stub from class.
3637 StorePointer(&raw_ptr()->allocation_stub_, Code::null()); 3631 StorePointer(&raw_ptr()->allocation_stub_, Code::null());
3638 } 3632 }
3639 3633
3640 3634
3641 bool Class::IsFunctionClass() const { 3635 bool Class::IsDartFunctionClass() const {
3642 return raw() == Type::Handle(Type::Function()).type_class(); 3636 return raw() == Type::Handle(Type::DartFunctionType()).type_class();
3643 } 3637 }
3644 3638
3645 3639
3646 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T. 3640 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T.
3647 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T. 3641 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T.
3648 // Type S is specified by this class parameterized with 'type_arguments', and 3642 // Type S is specified by this class parameterized with 'type_arguments', and
3649 // type T by class 'other' parameterized with 'other_type_arguments'. 3643 // type T by class 'other' parameterized with 'other_type_arguments'.
3650 // This class and class 'other' do not need to be finalized, however, they must 3644 // This class and class 'other' do not need to be finalized, however, they must
3651 // be resolved as well as their interfaces. 3645 // be resolved as well as their interfaces.
3652 bool Class::TypeTestNonRecursive(const Class& cls, 3646 bool Class::TypeTestNonRecursive(const Class& cls,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3710 return test_kind == Class::kIsSubtypeOf; 3704 return test_kind == Class::kIsSubtypeOf;
3711 } 3705 }
3712 return type_arguments.TypeTest(test_kind, 3706 return type_arguments.TypeTest(test_kind,
3713 other_type_arguments, 3707 other_type_arguments,
3714 from_index, 3708 from_index,
3715 num_type_params, 3709 num_type_params,
3716 bound_error, 3710 bound_error,
3717 bound_trail, 3711 bound_trail,
3718 space); 3712 space);
3719 } 3713 }
3720 if (other.IsFunctionClass()) { 3714 if (other.IsDartFunctionClass()) {
3721 // Check if type S has a call() method. 3715 // Check if type S has a call() method.
3722 Function& function = Function::Handle(zone, 3716 Function& function = Function::Handle(zone,
3723 thsi.LookupDynamicFunctionAllowAbstract(Symbols::Call())); 3717 thsi.LookupDynamicFunctionAllowAbstract(Symbols::Call()));
3724 if (function.IsNull()) { 3718 if (function.IsNull()) {
3725 // Walk up the super_class chain. 3719 // Walk up the super_class chain.
3726 Class& cls = Class::Handle(zone, thsi.SuperClass()); 3720 Class& cls = Class::Handle(zone, thsi.SuperClass());
3727 while (!cls.IsNull() && function.IsNull()) { 3721 while (!cls.IsNull() && function.IsNull()) {
3728 function = cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); 3722 function = cls.LookupDynamicFunctionAllowAbstract(Symbols::Call());
3729 cls = cls.SuperClass(); 3723 cls = cls.SuperClass();
3730 } 3724 }
(...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after
5432 ASSERT(obj.IsArray()); 5426 ASSERT(obj.IsArray());
5433 ASSERT((Array::Cast(obj).At(1) == Object::null()) || value.IsNull()); 5427 ASSERT((Array::Cast(obj).At(1) == Object::null()) || value.IsNull());
5434 Array::Cast(obj).SetAt(1, value); 5428 Array::Cast(obj).SetAt(1, value);
5435 } else { 5429 } else {
5436 ASSERT((raw_ptr()->data_ == Object::null()) || value.IsNull()); 5430 ASSERT((raw_ptr()->data_ == Object::null()) || value.IsNull());
5437 set_data(value); 5431 set_data(value);
5438 } 5432 }
5439 } 5433 }
5440 5434
5441 5435
5442 RawFunctionType* Function::SignatureType() const { 5436 RawType* Function::SignatureType() const {
5443 FunctionType& type = FunctionType::Handle(); 5437 Type& type = Type::Handle();
5444 const Object& obj = Object::Handle(raw_ptr()->data_); 5438 const Object& obj = Object::Handle(raw_ptr()->data_);
5445 if (IsSignatureFunction()) { 5439 if (IsSignatureFunction()) {
5446 ASSERT(obj.IsNull() || obj.IsFunctionType()); 5440 ASSERT(obj.IsNull() || Type::Cast(obj).IsFunctionType());
5447 type = obj.IsNull() ? FunctionType::null() : FunctionType::Cast(obj).raw(); 5441 type = obj.IsNull() ? Type::null() : Type::Cast(obj).raw();
5448 } else { 5442 } else {
5449 ASSERT(IsClosureFunction()); 5443 ASSERT(IsClosureFunction());
5450 ASSERT(!obj.IsNull()); 5444 ASSERT(!obj.IsNull());
5451 type = ClosureData::Cast(obj).signature_type(); 5445 type = ClosureData::Cast(obj).signature_type();
5452 } 5446 }
5453 if (type.IsNull()) { 5447 if (type.IsNull()) {
5454 // A function type is parameterized in the same way as the owner class of 5448 // A function type is parameterized in the same way as the owner class of
5455 // its non-static signature function. 5449 // its non-static signature function.
5456 // It is not type parameterized if its signature function is static. 5450 // It is not type parameterized if its signature function is static.
5457 // During type finalization, the type arguments of the super class of the 5451 // During type finalization, the type arguments of the super class of the
(...skipping 15 matching lines...) Expand all
5473 HasInstantiatedSignature())) { 5467 HasInstantiatedSignature())) {
5474 scope_class = Isolate::Current()->object_store()->closure_class(); 5468 scope_class = Isolate::Current()->object_store()->closure_class();
5475 if (IsSignatureFunction()) { 5469 if (IsSignatureFunction()) {
5476 set_owner(scope_class); 5470 set_owner(scope_class);
5477 set_token_pos(TokenPosition::kNoSource); 5471 set_token_pos(TokenPosition::kNoSource);
5478 } 5472 }
5479 } 5473 }
5480 const TypeArguments& signature_type_arguments = 5474 const TypeArguments& signature_type_arguments =
5481 TypeArguments::Handle(scope_class.type_parameters()); 5475 TypeArguments::Handle(scope_class.type_parameters());
5482 // Return the still unfinalized signature type. 5476 // Return the still unfinalized signature type.
5483 type = FunctionType::New(scope_class, 5477 type = Type::New(scope_class, signature_type_arguments, token_pos());
5484 signature_type_arguments, 5478 type.set_signature(*this);
5485 *this,
5486 token_pos());
5487
5488 SetSignatureType(type); 5479 SetSignatureType(type);
5489 } 5480 }
5490 return type.raw(); 5481 return type.raw();
5491 } 5482 }
5492 5483
5493 5484
5494 void Function::SetSignatureType(const FunctionType& value) const { 5485 void Function::SetSignatureType(const Type& value) const {
5495 if (IsSignatureFunction()) { 5486 if (IsSignatureFunction()) {
5496 set_data(value); 5487 set_data(value);
5497 } else { 5488 } else {
5498 ASSERT(IsClosureFunction()); 5489 ASSERT(IsClosureFunction());
5499 const Object& obj = Object::Handle(raw_ptr()->data_); 5490 const Object& obj = Object::Handle(raw_ptr()->data_);
5500 ASSERT(!obj.IsNull()); 5491 ASSERT(!obj.IsNull());
5501 ClosureData::Cast(obj).set_signature_type(value); 5492 ClosureData::Cast(obj).set_signature_type(value);
5502 } 5493 }
5503 } 5494 }
5504 5495
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
6153 other.token_pos(), 6144 other.token_pos(),
6154 Report::AtLocation, 6145 Report::AtLocation,
6155 Report::kError, 6146 Report::kError,
6156 Heap::kNew, 6147 Heap::kNew,
6157 "signature type '%s' of function '%s' is not a subtype of signature " 6148 "signature type '%s' of function '%s' is not a subtype of signature "
6158 "type '%s' of function '%s' where\n%s%s", 6149 "type '%s' of function '%s' where\n%s%s",
6159 String::Handle(UserVisibleSignature()).ToCString(), 6150 String::Handle(UserVisibleSignature()).ToCString(),
6160 String::Handle(UserVisibleName()).ToCString(), 6151 String::Handle(UserVisibleName()).ToCString(),
6161 String::Handle(other.UserVisibleSignature()).ToCString(), 6152 String::Handle(other.UserVisibleSignature()).ToCString(),
6162 String::Handle(other.UserVisibleName()).ToCString(), 6153 String::Handle(other.UserVisibleName()).ToCString(),
6163 String::Handle(FunctionType::Handle( 6154 String::Handle(Type::Handle(
6164 SignatureType()).EnumerateURIs()).ToCString(), 6155 SignatureType()).EnumerateURIs()).ToCString(),
6165 String::Handle(FunctionType::Handle( 6156 String::Handle(Type::Handle(
6166 other.SignatureType()).EnumerateURIs()).ToCString()); 6157 other.SignatureType()).EnumerateURIs()).ToCString());
6167 return false; 6158 return false;
6168 } 6159 }
6169 // We should also check that if the other function explicitly specifies a 6160 // We should also check that if the other function explicitly specifies a
6170 // default value for a formal parameter, this function does not specify a 6161 // default value for a formal parameter, this function does not specify a
6171 // different default value for the same parameter. However, this check is not 6162 // different default value for the same parameter. However, this check is not
6172 // possible in the current implementation, because the default parameter 6163 // possible in the current implementation, because the default parameter
6173 // values are not stored in the Function object, but discarded after a 6164 // values are not stored in the Function object, but discarded after a
6174 // function is compiled. 6165 // function is compiled.
6175 return true; 6166 return true;
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
6591 // Add implicit closure object parameter. 6582 // Add implicit closure object parameter.
6592 param_type = Type::DynamicType(); 6583 param_type = Type::DynamicType();
6593 closure_function.SetParameterTypeAt(0, param_type); 6584 closure_function.SetParameterTypeAt(0, param_type);
6594 closure_function.SetParameterNameAt(0, Symbols::ClosureParameter()); 6585 closure_function.SetParameterNameAt(0, Symbols::ClosureParameter());
6595 for (int i = kClosure; i < num_params; i++) { 6586 for (int i = kClosure; i < num_params; i++) {
6596 param_type = ParameterTypeAt(has_receiver - kClosure + i); 6587 param_type = ParameterTypeAt(has_receiver - kClosure + i);
6597 closure_function.SetParameterTypeAt(i, param_type); 6588 closure_function.SetParameterTypeAt(i, param_type);
6598 param_name = ParameterNameAt(has_receiver - kClosure + i); 6589 param_name = ParameterNameAt(has_receiver - kClosure + i);
6599 closure_function.SetParameterNameAt(i, param_name); 6590 closure_function.SetParameterNameAt(i, param_name);
6600 } 6591 }
6601 const FunctionType& signature_type = 6592 const Type& signature_type = Type::Handle(closure_function.SignatureType());
6602 FunctionType::Handle(closure_function.SignatureType());
6603 if (!signature_type.IsFinalized()) { 6593 if (!signature_type.IsFinalized()) {
6604 ClassFinalizer::FinalizeType( 6594 ClassFinalizer::FinalizeType(
6605 Class::Handle(Owner()), signature_type, ClassFinalizer::kCanonicalize); 6595 Class::Handle(Owner()), signature_type, ClassFinalizer::kCanonicalize);
6606 } 6596 }
6607 set_implicit_closure_function(closure_function); 6597 set_implicit_closure_function(closure_function);
6608 ASSERT(closure_function.IsImplicitClosureFunction()); 6598 ASSERT(closure_function.IsImplicitClosureFunction());
6609 return closure_function.raw(); 6599 return closure_function.raw();
6610 } 6600 }
6611 6601
6612 6602
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
6667 } 6657 }
6668 i++; 6658 i++;
6669 } 6659 }
6670 if (num_opt_params > 0) { 6660 if (num_opt_params > 0) {
6671 if (num_opt_pos_params > 0) { 6661 if (num_opt_pos_params > 0) {
6672 pieces->Add(Symbols::LBracket()); 6662 pieces->Add(Symbols::LBracket());
6673 } else { 6663 } else {
6674 pieces->Add(Symbols::LBrace()); 6664 pieces->Add(Symbols::LBrace());
6675 } 6665 }
6676 for (intptr_t i = num_fixed_params; i < num_params; i++) { 6666 for (intptr_t i = num_fixed_params; i < num_params; i++) {
6677 // The parameter name of an optional positional parameter does not need
6678 // to be part of the signature, since it is not used.
6679 if (num_opt_named_params > 0) {
6680 name = ParameterNameAt(i);
6681 pieces->Add(name);
6682 pieces->Add(Symbols::ColonSpace());
6683 }
6684 param_type = ParameterTypeAt(i); 6667 param_type = ParameterTypeAt(i);
6685 if (instantiate && 6668 if (instantiate &&
6686 param_type.IsFinalized() && 6669 param_type.IsFinalized() &&
6687 !param_type.IsInstantiated()) { 6670 !param_type.IsInstantiated()) {
6688 param_type = param_type.InstantiateFrom(instantiator, NULL, 6671 param_type = param_type.InstantiateFrom(instantiator, NULL,
6689 NULL, NULL, Heap::kNew); 6672 NULL, NULL, Heap::kNew);
6690 } 6673 }
6691 ASSERT(!param_type.IsNull()); 6674 ASSERT(!param_type.IsNull());
6692 name = param_type.BuildName(name_visibility); 6675 name = param_type.BuildName(name_visibility);
6693 pieces->Add(name); 6676 pieces->Add(name);
6677 // The parameter name of an optional positional parameter does not need
6678 // to be part of the signature, since it is not used.
6679 if (num_opt_named_params > 0) {
6680 name = ParameterNameAt(i);
6681 pieces->Add(Symbols::Blank());
6682 pieces->Add(name);
6683 }
6694 if (i != (num_params - 1)) { 6684 if (i != (num_params - 1)) {
6695 pieces->Add(Symbols::CommaSpace()); 6685 pieces->Add(Symbols::CommaSpace());
6696 } 6686 }
6697 } 6687 }
6698 if (num_opt_pos_params > 0) { 6688 if (num_opt_pos_params > 0) {
6699 pieces->Add(Symbols::RBracket()); 6689 pieces->Add(Symbols::RBracket());
6700 } else { 6690 } else {
6701 pieces->Add(Symbols::RBrace()); 6691 pieces->Add(Symbols::RBrace());
6702 } 6692 }
6703 } 6693 }
(...skipping 11 matching lines...) Expand all
6715 Instance& closure = 6705 Instance& closure =
6716 Instance::Handle(zone, Closure::New(*this, context, Heap::kOld)); 6706 Instance::Handle(zone, Closure::New(*this, context, Heap::kOld));
6717 set_implicit_static_closure(closure); 6707 set_implicit_static_closure(closure);
6718 } 6708 }
6719 return implicit_static_closure(); 6709 return implicit_static_closure();
6720 } 6710 }
6721 6711
6722 6712
6723 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const { 6713 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const {
6724 ASSERT(IsImplicitClosureFunction()); 6714 ASSERT(IsImplicitClosureFunction());
6725 const FunctionType& signature_type = FunctionType::Handle(SignatureType()); 6715 const Type& signature_type = Type::Handle(SignatureType());
6726 const Class& cls = Class::Handle(signature_type.type_class()); 6716 const Class& cls = Class::Handle(signature_type.type_class());
6727 const Context& context = Context::Handle(Context::New(1)); 6717 const Context& context = Context::Handle(Context::New(1));
6728 context.SetAt(0, receiver); 6718 context.SetAt(0, receiver);
6729 const Instance& result = Instance::Handle(Closure::New(*this, context)); 6719 const Instance& result = Instance::Handle(Closure::New(*this, context));
6730 if (cls.IsGeneric()) { 6720 if (cls.IsGeneric()) {
6731 const TypeArguments& type_arguments = 6721 const TypeArguments& type_arguments =
6732 TypeArguments::Handle(receiver.GetTypeArguments()); 6722 TypeArguments::Handle(receiver.GetTypeArguments());
6733 result.SetTypeArguments(type_arguments); 6723 result.SetTypeArguments(type_arguments);
6734 } 6724 }
6735 return result.raw(); 6725 return result.raw();
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
7127 ASSERT(raw_ptr()->closure_ == Instance::null()); 7117 ASSERT(raw_ptr()->closure_ == Instance::null());
7128 StorePointer(&raw_ptr()->closure_, closure.raw()); 7118 StorePointer(&raw_ptr()->closure_, closure.raw());
7129 } 7119 }
7130 7120
7131 7121
7132 void ClosureData::set_parent_function(const Function& value) const { 7122 void ClosureData::set_parent_function(const Function& value) const {
7133 StorePointer(&raw_ptr()->parent_function_, value.raw()); 7123 StorePointer(&raw_ptr()->parent_function_, value.raw());
7134 } 7124 }
7135 7125
7136 7126
7137 void ClosureData::set_signature_type(const FunctionType& value) const { 7127 void ClosureData::set_signature_type(const Type& value) const {
7138 StorePointer(&raw_ptr()->signature_type_, value.raw()); 7128 StorePointer(&raw_ptr()->signature_type_, value.raw());
7139 } 7129 }
7140 7130
7141 7131
7142 RawClosureData* ClosureData::New() { 7132 RawClosureData* ClosureData::New() {
7143 ASSERT(Object::closure_data_class() != Class::null()); 7133 ASSERT(Object::closure_data_class() != Class::null());
7144 RawObject* raw = Object::Allocate(ClosureData::kClassId, 7134 RawObject* raw = Object::Allocate(ClosureData::kClassId,
7145 ClosureData::InstanceSize(), 7135 ClosureData::InstanceSize(),
7146 Heap::kOld); 7136 Heap::kOld);
7147 return reinterpret_cast<RawClosureData*>(raw); 7137 return reinterpret_cast<RawClosureData*>(raw);
(...skipping 4945 matching lines...) Expand 10 before | Expand all | Expand 10 after
12093 ASSERT(!value.IsNull()); 12083 ASSERT(!value.IsNull());
12094 StorePointer(&raw_ptr()->target_name_, value.raw()); 12084 StorePointer(&raw_ptr()->target_name_, value.raw());
12095 } 12085 }
12096 12086
12097 12087
12098 void ICData::set_arguments_descriptor(const Array& value) const { 12088 void ICData::set_arguments_descriptor(const Array& value) const {
12099 ASSERT(!value.IsNull()); 12089 ASSERT(!value.IsNull());
12100 StorePointer(&raw_ptr()->args_descriptor_, value.raw()); 12090 StorePointer(&raw_ptr()->args_descriptor_, value.raw());
12101 } 12091 }
12102 12092
12093
12103 void ICData::set_deopt_id(intptr_t value) const { 12094 void ICData::set_deopt_id(intptr_t value) const {
12104 ASSERT(value <= kMaxInt32); 12095 ASSERT(value <= kMaxInt32);
12105 StoreNonPointer(&raw_ptr()->deopt_id_, value); 12096 StoreNonPointer(&raw_ptr()->deopt_id_, value);
12106 } 12097 }
12107 12098
12108 12099
12109 void ICData::set_ic_data_array(const Array& value) const { 12100 void ICData::set_ic_data_array(const Array& value) const {
12110 ASSERT(!value.IsNull()); 12101 ASSERT(!value.IsNull());
12111 StorePointer(&raw_ptr()->ic_data_, value.raw()); 12102 StorePointer(&raw_ptr()->ic_data_, value.raw());
12112 } 12103 }
(...skipping 2499 matching lines...) Expand 10 before | Expand all | Expand 10 after
14612 14603
14613 14604
14614 RawAbstractType* Instance::GetType() const { 14605 RawAbstractType* Instance::GetType() const {
14615 if (IsNull()) { 14606 if (IsNull()) {
14616 return Type::NullType(); 14607 return Type::NullType();
14617 } 14608 }
14618 const Class& cls = Class::Handle(clazz()); 14609 const Class& cls = Class::Handle(clazz());
14619 if (cls.IsClosureClass()) { 14610 if (cls.IsClosureClass()) {
14620 const Function& signature = 14611 const Function& signature =
14621 Function::Handle(Closure::Cast(*this).function()); 14612 Function::Handle(Closure::Cast(*this).function());
14622 FunctionType& type = FunctionType::Handle(signature.SignatureType()); 14613 Type& type = Type::Handle(signature.SignatureType());
14623 if (type.scope_class() == cls.raw()) { 14614 if (type.type_class() == cls.raw()) {
14624 // Type is not parameterized. 14615 // Type is not parameterized.
14625 if (!type.IsCanonical()) { 14616 if (!type.IsCanonical()) {
14626 type ^= type.Canonicalize(); 14617 type ^= type.Canonicalize();
14627 signature.SetSignatureType(type); 14618 signature.SetSignatureType(type);
14628 } 14619 }
14629 return type.raw(); 14620 return type.raw();
14630 } 14621 }
14631 const Class& scope_cls = Class::Handle(type.scope_class()); 14622 const Class& scope_cls = Class::Handle(type.type_class());
14632 ASSERT(scope_cls.NumTypeArguments() > 0); 14623 ASSERT(scope_cls.NumTypeArguments() > 0);
14633 TypeArguments& type_arguments = TypeArguments::Handle(GetTypeArguments()); 14624 TypeArguments& type_arguments = TypeArguments::Handle(GetTypeArguments());
14634 type = FunctionType::New( 14625 type = Type::New(scope_cls, type_arguments, TokenPosition::kNoSource);
14635 scope_cls, type_arguments, signature, TokenPosition::kNoSource); 14626 type.set_signature(signature);
14636 type.SetIsFinalized(); 14627 type.SetIsFinalized();
14637 type ^= type.Canonicalize(); 14628 type ^= type.Canonicalize();
14638 return type.raw(); 14629 return type.raw();
14639 } 14630 }
14640 Type& type = Type::Handle(); 14631 Type& type = Type::Handle();
14641 if (!cls.IsGeneric()) { 14632 if (!cls.IsGeneric()) {
14642 type = cls.CanonicalType(); 14633 type = cls.CanonicalType();
14643 } 14634 }
14644 if (type.IsNull()) { 14635 if (type.IsNull()) {
14645 TypeArguments& type_arguments = TypeArguments::Handle(); 14636 TypeArguments& type_arguments = TypeArguments::Handle();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
14705 instantiated_other = TypeRef::Cast(instantiated_other).type(); 14696 instantiated_other = TypeRef::Cast(instantiated_other).type();
14706 } 14697 }
14707 if (instantiated_other.IsDynamicType() || 14698 if (instantiated_other.IsDynamicType() ||
14708 instantiated_other.IsObjectType() || 14699 instantiated_other.IsObjectType() ||
14709 instantiated_other.IsDartFunctionType()) { 14700 instantiated_other.IsDartFunctionType()) {
14710 return true; 14701 return true;
14711 } 14702 }
14712 if (!instantiated_other.IsFunctionType()) { 14703 if (!instantiated_other.IsFunctionType()) {
14713 return false; 14704 return false;
14714 } 14705 }
14715 other_signature = FunctionType::Cast(instantiated_other).signature(); 14706 other_signature = Type::Cast(instantiated_other).signature();
14716 other_type_arguments = instantiated_other.arguments(); 14707 other_type_arguments = instantiated_other.arguments();
14717 } else { 14708 } else {
14718 if (!other.IsFunctionType()) { 14709 if (!other.IsFunctionType()) {
14719 return false; 14710 return false;
14720 } 14711 }
14721 other_signature = FunctionType::Cast(other).signature(); 14712 other_signature = Type::Cast(other).signature();
14722 other_type_arguments = other.arguments(); 14713 other_type_arguments = other.arguments();
14723 } 14714 }
14724 const Function& signature = 14715 const Function& signature =
14725 Function::Handle(zone, Closure::Cast(*this).function()); 14716 Function::Handle(zone, Closure::Cast(*this).function());
14726 const TypeArguments& type_arguments = 14717 const TypeArguments& type_arguments =
14727 TypeArguments::Handle(zone, GetTypeArguments()); 14718 TypeArguments::Handle(zone, GetTypeArguments());
14728 return signature.IsSubtypeOf(type_arguments, 14719 return signature.IsSubtypeOf(type_arguments,
14729 other_signature, 14720 other_signature,
14730 other_type_arguments, 14721 other_type_arguments,
14731 bound_error, 14722 bound_error,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
14776 while (!super_cls.IsNull() && call.IsNull()) { 14767 while (!super_cls.IsNull() && call.IsNull()) {
14777 call = super_cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); 14768 call = super_cls.LookupDynamicFunctionAllowAbstract(Symbols::Call());
14778 super_cls = super_cls.SuperClass(); 14769 super_cls = super_cls.SuperClass();
14779 } 14770 }
14780 } 14771 }
14781 if (!call.IsNull()) { 14772 if (!call.IsNull()) {
14782 if (other_is_dart_function) { 14773 if (other_is_dart_function) {
14783 return true; 14774 return true;
14784 } 14775 }
14785 const Function& other_signature = Function::Handle( 14776 const Function& other_signature = Function::Handle(
14786 zone, FunctionType::Cast(instantiated_other).signature()); 14777 zone, Type::Cast(instantiated_other).signature());
14787 if (call.IsSubtypeOf(type_arguments, 14778 if (call.IsSubtypeOf(type_arguments,
14788 other_signature, 14779 other_signature,
14789 other_type_arguments, 14780 other_type_arguments,
14790 bound_error, 14781 bound_error,
14791 Heap::kOld)) { 14782 Heap::kOld)) {
14792 return true; 14783 return true;
14793 } 14784 }
14794 } 14785 }
14795 } 14786 }
14796 if (!instantiated_other.IsType()) { 14787 if (!instantiated_other.IsType()) {
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
15273 // a malformed type, so proceed with caution. 15264 // a malformed type, so proceed with caution.
15274 const TypeArguments& args = TypeArguments::Handle(zone, arguments()); 15265 const TypeArguments& args = TypeArguments::Handle(zone, arguments());
15275 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); 15266 const intptr_t num_args = args.IsNull() ? 0 : args.Length();
15276 String& class_name = String::Handle(zone); 15267 String& class_name = String::Handle(zone);
15277 intptr_t first_type_param_index; 15268 intptr_t first_type_param_index;
15278 intptr_t num_type_params; // Number of type parameters to print. 15269 intptr_t num_type_params; // Number of type parameters to print.
15279 Class& cls = Class::Handle(zone); 15270 Class& cls = Class::Handle(zone);
15280 if (IsFunctionType()) { 15271 if (IsFunctionType()) {
15281 cls = type_class(); 15272 cls = type_class();
15282 const Function& signature_function = Function::Handle( 15273 const Function& signature_function = Function::Handle(
15283 zone, FunctionType::Cast(*this).signature()); 15274 zone, Type::Cast(*this).signature());
15284 if (!cls.IsTypedefClass() || 15275 if (!cls.IsTypedefClass() ||
15285 (cls.signature_function() != signature_function.raw())) { 15276 (cls.signature_function() != signature_function.raw())) {
15286 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { 15277 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) {
15287 return signature_function.UserVisibleSignature(); 15278 return signature_function.UserVisibleSignature();
15288 } 15279 }
15289 return signature_function.InstantiatedSignatureFrom(args, 15280 return signature_function.InstantiatedSignatureFrom(args,
15290 name_visibility); 15281 name_visibility);
15291 } 15282 }
15292 class_name = cls.Name(); // Typedef name. 15283 class_name = cls.Name(); // Typedef name.
15293 // We may be reporting an error about a malformed function type. In that 15284 // We may be reporting an error about a malformed function type. In that
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
15378 pieces.Add(String::Handle(zone, BuildName(kUserVisibleName))); 15369 pieces.Add(String::Handle(zone, BuildName(kUserVisibleName)));
15379 if (!IsDynamicType() && !IsVoidType()) { 15370 if (!IsDynamicType() && !IsVoidType()) {
15380 pieces.Add(Symbols::SpaceWhereNewLine()); 15371 pieces.Add(Symbols::SpaceWhereNewLine());
15381 pieces.Add(String::Handle(zone, EnumerateURIs())); 15372 pieces.Add(String::Handle(zone, EnumerateURIs()));
15382 } 15373 }
15383 return Symbols::FromConcatAll(pieces); 15374 return Symbols::FromConcatAll(pieces);
15384 } 15375 }
15385 15376
15386 15377
15387 RawString* AbstractType::ClassName() const { 15378 RawString* AbstractType::ClassName() const {
15379 ASSERT(!IsFunctionType());
15388 if (HasResolvedTypeClass()) { 15380 if (HasResolvedTypeClass()) {
15389 return Class::Handle(type_class()).Name(); 15381 return Class::Handle(type_class()).Name();
15390 } else { 15382 } else {
15391 return UnresolvedClass::Handle(unresolved_class()).Name(); 15383 return UnresolvedClass::Handle(unresolved_class()).Name();
15392 } 15384 }
15393 } 15385 }
15394 15386
15395 15387
15396 bool AbstractType::IsNullType() const { 15388 bool AbstractType::IsNullType() const {
15397 return HasResolvedTypeClass() && 15389 return !IsFunctionType() &&
15390 HasResolvedTypeClass() &&
15398 (type_class() == Isolate::Current()->object_store()->null_class()); 15391 (type_class() == Isolate::Current()->object_store()->null_class());
15399 } 15392 }
15400 15393
15401 15394
15402 bool AbstractType::IsBoolType() const { 15395 bool AbstractType::IsBoolType() const {
15403 return HasResolvedTypeClass() && 15396 return !IsFunctionType() &&
15397 HasResolvedTypeClass() &&
15404 (type_class() == Isolate::Current()->object_store()->bool_class()); 15398 (type_class() == Isolate::Current()->object_store()->bool_class());
15405 } 15399 }
15406 15400
15407 15401
15408 bool AbstractType::IsIntType() const { 15402 bool AbstractType::IsIntType() const {
15409 return HasResolvedTypeClass() && 15403 return !IsFunctionType() &&
15404 HasResolvedTypeClass() &&
15410 (type_class() == Type::Handle(Type::IntType()).type_class()); 15405 (type_class() == Type::Handle(Type::IntType()).type_class());
15411 } 15406 }
15412 15407
15413 15408
15414 bool AbstractType::IsDoubleType() const { 15409 bool AbstractType::IsDoubleType() const {
15415 return HasResolvedTypeClass() && 15410 return !IsFunctionType() &&
15411 HasResolvedTypeClass() &&
15416 (type_class() == Type::Handle(Type::Double()).type_class()); 15412 (type_class() == Type::Handle(Type::Double()).type_class());
15417 } 15413 }
15418 15414
15419 15415
15420 bool AbstractType::IsFloat32x4Type() const { 15416 bool AbstractType::IsFloat32x4Type() const {
15421 return HasResolvedTypeClass() && 15417 return !IsFunctionType() &&
15418 HasResolvedTypeClass() &&
15422 (type_class() == Type::Handle(Type::Float32x4()).type_class()); 15419 (type_class() == Type::Handle(Type::Float32x4()).type_class());
15423 } 15420 }
15424 15421
15425 15422
15426 bool AbstractType::IsFloat64x2Type() const { 15423 bool AbstractType::IsFloat64x2Type() const {
15427 return HasResolvedTypeClass() && 15424 return !IsFunctionType() &&
15425 HasResolvedTypeClass() &&
15428 (type_class() == Type::Handle(Type::Float64x2()).type_class()); 15426 (type_class() == Type::Handle(Type::Float64x2()).type_class());
15429 } 15427 }
15430 15428
15431 15429
15432 bool AbstractType::IsInt32x4Type() const { 15430 bool AbstractType::IsInt32x4Type() const {
15433 return HasResolvedTypeClass() && 15431 return !IsFunctionType() &&
15432 HasResolvedTypeClass() &&
15434 (type_class() == Type::Handle(Type::Int32x4()).type_class()); 15433 (type_class() == Type::Handle(Type::Int32x4()).type_class());
15435 } 15434 }
15436 15435
15437 15436
15438 bool AbstractType::IsNumberType() const { 15437 bool AbstractType::IsNumberType() const {
15439 return HasResolvedTypeClass() && 15438 return !IsFunctionType() &&
15439 HasResolvedTypeClass() &&
15440 (type_class() == Type::Handle(Type::Number()).type_class()); 15440 (type_class() == Type::Handle(Type::Number()).type_class());
15441 } 15441 }
15442 15442
15443 15443
15444 bool AbstractType::IsSmiType() const { 15444 bool AbstractType::IsSmiType() const {
15445 return HasResolvedTypeClass() && 15445 return !IsFunctionType() &&
15446 HasResolvedTypeClass() &&
15446 (type_class() == Type::Handle(Type::SmiType()).type_class()); 15447 (type_class() == Type::Handle(Type::SmiType()).type_class());
15447 } 15448 }
15448 15449
15449 15450
15450 bool AbstractType::IsStringType() const { 15451 bool AbstractType::IsStringType() const {
15451 return HasResolvedTypeClass() && 15452 return !IsFunctionType() &&
15453 HasResolvedTypeClass() &&
15452 (type_class() == Type::Handle(Type::StringType()).type_class()); 15454 (type_class() == Type::Handle(Type::StringType()).type_class());
15453 } 15455 }
15454 15456
15455 15457
15456 bool AbstractType::IsDartFunctionType() const { 15458 bool AbstractType::IsDartFunctionType() const {
15457 return HasResolvedTypeClass() && 15459 return !IsFunctionType() &&
15458 (type_class() == Type::Handle(Type::Function()).type_class()); 15460 HasResolvedTypeClass() &&
15461 (type_class() == Type::Handle(Type::DartFunctionType()).type_class());
15459 } 15462 }
15460 15463
15461 15464
15462 bool AbstractType::TypeTest(TypeTestKind test_kind, 15465 bool AbstractType::TypeTest(TypeTestKind test_kind,
15463 const AbstractType& other, 15466 const AbstractType& other,
15464 Error* bound_error, 15467 Error* bound_error,
15465 TrailPtr bound_trail, 15468 TrailPtr bound_trail,
15466 Heap::Space space) const { 15469 Heap::Space space) const {
15467 ASSERT(IsFinalized()); 15470 ASSERT(IsFinalized());
15468 ASSERT(other.IsFinalized()); 15471 ASSERT(other.IsFinalized());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
15546 if (other.IsTypeParameter()) { 15549 if (other.IsTypeParameter()) {
15547 const TypeParameter& other_type_param = TypeParameter::Cast(other); 15550 const TypeParameter& other_type_param = TypeParameter::Cast(other);
15548 if (type_param.Equals(other_type_param)) { 15551 if (type_param.Equals(other_type_param)) {
15549 return true; 15552 return true;
15550 } 15553 }
15551 } 15554 }
15552 const AbstractType& bound = AbstractType::Handle(zone, type_param.bound()); 15555 const AbstractType& bound = AbstractType::Handle(zone, type_param.bound());
15553 // We may be checking bounds at finalization time and can encounter 15556 // We may be checking bounds at finalization time and can encounter
15554 // a still unfinalized bound. Finalizing the bound here may lead to cycles. 15557 // a still unfinalized bound. Finalizing the bound here may lead to cycles.
15555 if (!bound.IsFinalized()) { 15558 if (!bound.IsFinalized()) {
15556 return false; // TODO(regis): Return "maybe after instantiation". 15559 return false; // TODO(regis): Return "maybe after instantiation".
15557 } 15560 }
15558 // The current bound_trail cannot be used, because operands are swapped and 15561 // The current bound_trail cannot be used, because operands are swapped and
15559 // the test is different anyway (more specific vs. subtype). 15562 // the test is different anyway (more specific vs. subtype).
15560 if (bound.IsMoreSpecificThan(other, bound_error, NULL, space)) { 15563 if (bound.IsMoreSpecificThan(other, bound_error, NULL, space)) {
15561 return true; 15564 return true;
15562 } 15565 }
15563 return false; // TODO(regis): We should return "maybe after instantiation". 15566 return false; // TODO(regis): We should return "maybe after instantiation".
15564 } 15567 }
15565 if (other.IsTypeParameter()) { 15568 if (other.IsTypeParameter()) {
15566 return false; // TODO(regis): We should return "maybe after instantiation". 15569 return false; // TODO(regis): We should return "maybe after instantiation".
15567 } 15570 }
15568 const Class& type_cls = Class::Handle(zone, type_class()); 15571 const Class& type_cls = Class::Handle(zone, type_class());
15569 // Function types cannot be handled by Class::TypeTest(). 15572 // Function types cannot be handled by Class::TypeTest().
15570 const bool other_is_dart_function_type = other.IsDartFunctionType(); 15573 const bool other_is_dart_function_type = other.IsDartFunctionType();
15571 if (other_is_dart_function_type || other.IsFunctionType()) { 15574 if (other_is_dart_function_type || other.IsFunctionType()) {
15572 if (IsFunctionType()) { 15575 if (IsFunctionType()) {
15573 if (other_is_dart_function_type) { 15576 if (other_is_dart_function_type) {
15574 return true; 15577 return true;
15575 } 15578 }
15576 const Function& other_fun = 15579 const Function& other_fun =
15577 Function::Handle(zone, FunctionType::Cast(other).signature()); 15580 Function::Handle(zone, Type::Cast(other).signature());
15578 // Check for two function types. 15581 // Check for two function types.
15579 const Function& fun = 15582 const Function& fun =
15580 Function::Handle(zone, FunctionType::Cast(*this).signature()); 15583 Function::Handle(zone, Type::Cast(*this).signature());
15581 return fun.TypeTest(test_kind, 15584 return fun.TypeTest(test_kind,
15582 TypeArguments::Handle(zone, arguments()), 15585 TypeArguments::Handle(zone, arguments()),
15583 other_fun, 15586 other_fun,
15584 TypeArguments::Handle(zone, other.arguments()), 15587 TypeArguments::Handle(zone, other.arguments()),
15585 bound_error, 15588 bound_error,
15586 space); 15589 space);
15587 } 15590 }
15588 // Check if type S has a call() method of function type T. 15591 // Check if type S has a call() method of function type T.
15589 Function& function = Function::Handle(zone, 15592 Function& function = Function::Handle(zone,
15590 type_cls.LookupDynamicFunctionAllowAbstract(Symbols::Call())); 15593 type_cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()));
15591 if (function.IsNull()) { 15594 if (function.IsNull()) {
15592 // Walk up the super_class chain. 15595 // Walk up the super_class chain.
15593 Class& cls = Class::Handle(zone, type_cls.SuperClass()); 15596 Class& cls = Class::Handle(zone, type_cls.SuperClass());
15594 while (!cls.IsNull() && function.IsNull()) { 15597 while (!cls.IsNull() && function.IsNull()) {
15595 function = cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); 15598 function = cls.LookupDynamicFunctionAllowAbstract(Symbols::Call());
15596 cls = cls.SuperClass(); 15599 cls = cls.SuperClass();
15597 } 15600 }
15598 } 15601 }
15599 if (!function.IsNull()) { 15602 if (!function.IsNull()) {
15600 if (other_is_dart_function_type || 15603 if (other_is_dart_function_type ||
15601 function.TypeTest(test_kind, 15604 function.TypeTest(test_kind,
15602 TypeArguments::Handle(zone, arguments()), 15605 TypeArguments::Handle(zone, arguments()),
15603 Function::Handle( 15606 Function::Handle(
15604 zone, FunctionType::Cast(other).signature()), 15607 zone, Type::Cast(other).signature()),
15605 TypeArguments::Handle(zone, other.arguments()), 15608 TypeArguments::Handle(zone, other.arguments()),
15606 bound_error, 15609 bound_error,
15607 space)) { 15610 space)) {
15608 return true; 15611 return true;
15609 } 15612 }
15610 } 15613 }
15611 } 15614 }
15612 if (IsFunctionType()) { 15615 if (IsFunctionType()) {
15613 return false; 15616 return false;
15614 } 15617 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
15704 RawType* Type::StringType() { 15707 RawType* Type::StringType() {
15705 return Isolate::Current()->object_store()->string_type(); 15708 return Isolate::Current()->object_store()->string_type();
15706 } 15709 }
15707 15710
15708 15711
15709 RawType* Type::ArrayType() { 15712 RawType* Type::ArrayType() {
15710 return Isolate::Current()->object_store()->array_type(); 15713 return Isolate::Current()->object_store()->array_type();
15711 } 15714 }
15712 15715
15713 15716
15714 RawType* Type::Function() { 15717 RawType* Type::DartFunctionType() {
15715 return Isolate::Current()->object_store()->function_type(); 15718 return Isolate::Current()->object_store()->function_type();
15716 } 15719 }
15717 15720
15718 15721
15719 RawType* Type::NewNonParameterizedType(const Class& type_class) { 15722 RawType* Type::NewNonParameterizedType(const Class& type_class) {
15720 ASSERT(type_class.NumTypeArguments() == 0); 15723 ASSERT(type_class.NumTypeArguments() == 0);
15721 Type& type = Type::Handle(type_class.CanonicalType()); 15724 Type& type = Type::Handle(type_class.CanonicalType());
15722 if (type.IsNull()) { 15725 if (type.IsNull()) {
15723 const TypeArguments& no_type_arguments = TypeArguments::Handle(); 15726 const TypeArguments& no_type_arguments = TypeArguments::Handle();
15724 type ^= Type::New(Object::Handle(type_class.raw()), 15727 type ^= Type::New(Object::Handle(type_class.raw()),
(...skipping 11 matching lines...) Expand all
15736 ASSERT(!IsFinalized()); 15739 ASSERT(!IsFinalized());
15737 if (IsInstantiated()) { 15740 if (IsInstantiated()) {
15738 ASSERT(HasResolvedTypeClass()); 15741 ASSERT(HasResolvedTypeClass());
15739 set_type_state(RawType::kFinalizedInstantiated); 15742 set_type_state(RawType::kFinalizedInstantiated);
15740 } else { 15743 } else {
15741 set_type_state(RawType::kFinalizedUninstantiated); 15744 set_type_state(RawType::kFinalizedUninstantiated);
15742 } 15745 }
15743 } 15746 }
15744 15747
15745 15748
15749 void Type::ResetIsFinalized() const {
15750 ASSERT(IsFinalized());
15751 set_type_state(RawType::kBeingFinalized);
15752 SetIsFinalized();
15753 }
15754
15755
15746 void Type::SetIsBeingFinalized() const { 15756 void Type::SetIsBeingFinalized() const {
15747 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized()); 15757 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized());
15748 set_type_state(RawType::kBeingFinalized); 15758 set_type_state(RawType::kBeingFinalized);
15749 } 15759 }
15750 15760
15751 15761
15752 bool Type::IsMalformed() const { 15762 bool Type::IsMalformed() const {
15753 if (raw_ptr()->error_ == LanguageError::null()) { 15763 if (raw_ptr()->sig_or_err_.error_ == LanguageError::null()) {
15754 return false; 15764 return false; // Valid type, but not a function type.
15755 } 15765 }
15756 const LanguageError& type_error = LanguageError::Handle(error()); 15766 const LanguageError& type_error = LanguageError::Handle(error());
15767 if (type_error.IsNull()) {
15768 return false; // Valid function type.
15769 }
15757 return type_error.kind() == Report::kMalformedType; 15770 return type_error.kind() == Report::kMalformedType;
15758 } 15771 }
15759 15772
15760 15773
15761 bool Type::IsMalbounded() const { 15774 bool Type::IsMalbounded() const {
15775 if (raw_ptr()->sig_or_err_.error_ == LanguageError::null()) {
15776 return false; // Valid type, but not a function type.
15777 }
15762 if (!Isolate::Current()->type_checks()) { 15778 if (!Isolate::Current()->type_checks()) {
15763 return false; 15779 return false;
15764 } 15780 }
15765 if (raw_ptr()->error_ == LanguageError::null()) { 15781 const LanguageError& type_error = LanguageError::Handle(error());
15766 return false; 15782 if (type_error.IsNull()) {
15783 return false; // Valid function type.
15767 } 15784 }
15768 const LanguageError& type_error = LanguageError::Handle(error());
15769 return type_error.kind() == Report::kMalboundedType; 15785 return type_error.kind() == Report::kMalboundedType;
15770 } 15786 }
15771 15787
15772 15788
15773 bool Type::IsMalformedOrMalbounded() const { 15789 bool Type::IsMalformedOrMalbounded() const {
15774 if (raw_ptr()->error_ == LanguageError::null()) { 15790 if (raw_ptr()->sig_or_err_.error_ == LanguageError::null()) {
15775 return false; 15791 return false; // Valid type, but not a function type.
15776 } 15792 }
15777 const LanguageError& type_error = LanguageError::Handle(error()); 15793 const LanguageError& type_error = LanguageError::Handle(error());
15794 if (type_error.IsNull()) {
15795 return false; // Valid function type.
15796 }
15778 if (type_error.kind() == Report::kMalformedType) { 15797 if (type_error.kind() == Report::kMalformedType) {
15779 return true; 15798 return true;
15780 } 15799 }
15781 ASSERT(type_error.kind() == Report::kMalboundedType); 15800 ASSERT(type_error.kind() == Report::kMalboundedType);
15782 return Isolate::Current()->type_checks(); 15801 return Isolate::Current()->type_checks();
15783 } 15802 }
15784 15803
15785 15804
15805 RawLanguageError* Type::error() const {
15806 const Object& type_error = Object::Handle(raw_ptr()->sig_or_err_.error_);
15807 if (type_error.IsLanguageError()) {
15808 return LanguageError::RawCast(type_error.raw());
15809 }
15810 return LanguageError::null();
15811 }
15812
15813
15786 void Type::set_error(const LanguageError& value) const { 15814 void Type::set_error(const LanguageError& value) const {
15787 StorePointer(&raw_ptr()->error_, value.raw()); 15815 StorePointer(&raw_ptr()->sig_or_err_.error_, value.raw());
15816 }
15817
15818
15819 RawFunction* Type::signature() const {
15820 if (raw_ptr()->sig_or_err_.signature_ == Function::null()) {
15821 return Function::null();
15822 }
15823 const Object& obj = Object::Handle(raw_ptr()->sig_or_err_.signature_);
15824 if (obj.IsFunction()) {
15825 return Function::RawCast(obj.raw());
15826 }
15827 ASSERT(obj.IsLanguageError()); // Type is malformed or malbounded.
15828 return Function::null();
15829 }
15830
15831
15832 void Type::set_signature(const Function& value) const {
15833 StorePointer(&raw_ptr()->sig_or_err_.signature_, value.raw());
15788 } 15834 }
15789 15835
15790 15836
15791 void Type::SetIsResolved() const { 15837 void Type::SetIsResolved() const {
15792 ASSERT(!IsResolved()); 15838 ASSERT(!IsResolved());
15793 // A Typedef is a FunctionType, not a type.
15794 ASSERT(!Class::Handle(type_class()).IsTypedefClass());
15795 set_type_state(RawType::kResolved); 15839 set_type_state(RawType::kResolved);
15796 } 15840 }
15797 15841
15798 15842
15799 bool Type::HasResolvedTypeClass() const { 15843 bool Type::HasResolvedTypeClass() const {
15800 const Object& type_class = Object::Handle(raw_ptr()->type_class_); 15844 const Object& type_class = Object::Handle(raw_ptr()->type_class_);
15801 return !type_class.IsNull() && type_class.IsClass(); 15845 return !type_class.IsNull() && type_class.IsClass();
15802 } 15846 }
15803 15847
15804 15848
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
15885 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); 15929 ASSERT(type_arguments.Length() == cls.NumTypeArguments());
15886 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, 15930 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments,
15887 bound_error, 15931 bound_error,
15888 instantiation_trail, 15932 instantiation_trail,
15889 bound_trail, 15933 bound_trail,
15890 space); 15934 space);
15891 // This uninstantiated type is not modified, as it can be instantiated 15935 // This uninstantiated type is not modified, as it can be instantiated
15892 // with different instantiators. Allocate a new instantiated version of it. 15936 // with different instantiators. Allocate a new instantiated version of it.
15893 const Type& instantiated_type = 15937 const Type& instantiated_type =
15894 Type::Handle(zone, Type::New(cls, type_arguments, token_pos(), space)); 15938 Type::Handle(zone, Type::New(cls, type_arguments, token_pos(), space));
15939 // Preserve the bound error if any.
15940 if (IsMalbounded()) {
15941 const LanguageError& bound_error = LanguageError::Handle(zone, error());
15942 instantiated_type.set_error(bound_error);
15943 }
15944 // Preserve the signature if this type represents a function type.
15945 // Note that the types in the signature remain unchanged. They get indirectly
15946 // instantiated by instantiating the type arguments above.
15947 const Function& sig_fun = Function::Handle(zone, signature());
15948 if (!sig_fun.IsNull()) {
15949 instantiated_type.set_signature(sig_fun);
15950 }
15895 if (IsFinalized()) { 15951 if (IsFinalized()) {
15896 instantiated_type.SetIsFinalized(); 15952 instantiated_type.SetIsFinalized();
15897 } else { 15953 } else {
15898 instantiated_type.SetIsResolved(); 15954 instantiated_type.SetIsResolved();
15899 } 15955 }
15900 // Canonicalization is not part of instantiation. 15956 // Canonicalization is not part of instantiation.
15901 return instantiated_type.raw(); 15957 return instantiated_type.raw();
15902 } 15958 }
15903 15959
15904 15960
15905 bool Type::IsEquivalent(const Instance& other, TrailPtr trail) const { 15961 bool Type::IsEquivalent(const Instance& other, TrailPtr trail) const {
15906 ASSERT(!IsNull()); 15962 ASSERT(!IsNull());
15907 if (raw() == other.raw()) { 15963 if (raw() == other.raw()) {
15908 return true; 15964 return true;
15909 } 15965 }
15910 if (other.IsTypeRef()) { 15966 if (other.IsTypeRef()) {
15911 // Unfold right hand type. Divergence is controlled by left hand type. 15967 // Unfold right hand type. Divergence is controlled by left hand type.
15912 const AbstractType& other_ref_type = AbstractType::Handle( 15968 const AbstractType& other_ref_type = AbstractType::Handle(
15913 TypeRef::Cast(other).type()); 15969 TypeRef::Cast(other).type());
15914 ASSERT(!other_ref_type.IsTypeRef()); 15970 ASSERT(!other_ref_type.IsTypeRef());
15915 return IsEquivalent(other_ref_type, trail); 15971 return IsEquivalent(other_ref_type, trail);
15916 } 15972 }
15917 if (!other.IsType()) { 15973 if (!other.IsType()) {
15918 return false; 15974 return false;
15919 } 15975 }
15920 const Type& other_type = Type::Cast(other); 15976 const Type& other_type = Type::Cast(other);
15977 if (IsFunctionType() != other_type.IsFunctionType()) {
15978 return false;
15979 }
15921 ASSERT(IsResolved() && other_type.IsResolved()); 15980 ASSERT(IsResolved() && other_type.IsResolved());
15922 if (IsMalformed() || other_type.IsMalformed()) { 15981 if (IsMalformed() || other_type.IsMalformed()) {
15923 return false; 15982 return false; // Malformed types do not get canonicalized.
15983 }
15984 if (IsMalbounded() != other_type.IsMalbounded()) {
15985 return false; // Do not drop bound error.
15924 } 15986 }
15925 if (type_class() != other_type.type_class()) { 15987 if (type_class() != other_type.type_class()) {
15926 return false; 15988 return false;
15927 } 15989 }
15928 if (!IsFinalized() || !other_type.IsFinalized()) { 15990 if (!IsFinalized() || !other_type.IsFinalized()) {
15929 return false; 15991 return false; // Too early to decide if equal.
15930 } 15992 }
15931 if (arguments() == other_type.arguments()) { 15993 if ((arguments() == other_type.arguments()) &&
15994 (signature() == other_type.signature())) {
15932 return true; 15995 return true;
15933 } 15996 }
15934 Thread* thread = Thread::Current(); 15997 Thread* thread = Thread::Current();
15935 Zone* zone = thread->zone(); 15998 Zone* zone = thread->zone();
15999 if (arguments() != other_type.arguments()) {
15936 const Class& cls = Class::Handle(zone, type_class()); 16000 const Class& cls = Class::Handle(zone, type_class());
15937 const intptr_t num_type_params = cls.NumTypeParameters(thread); 16001 const intptr_t num_type_params = cls.NumTypeParameters(thread);
15938 if (num_type_params == 0) { 16002 // Shortcut unnecessary handle allocation below if non-generic.
15939 // Shortcut unnecessary handle allocation below. 16003 if (num_type_params > 0) {
16004 const intptr_t num_type_args = cls.NumTypeArguments();
16005 const intptr_t from_index = num_type_args - num_type_params;
16006 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16007 const TypeArguments& other_type_args = TypeArguments::Handle(
16008 zone, other_type.arguments());
16009 if (type_args.IsNull()) {
16010 // Ignore from_index.
16011 if (!other_type_args.IsRaw(0, num_type_args)) {
16012 return false;
16013 }
16014 } else if (other_type_args.IsNull()) {
16015 // Ignore from_index.
16016 if (!type_args.IsRaw(0, num_type_args)) {
16017 return false;
16018 }
16019 } else if (!type_args.IsSubvectorEquivalent(other_type_args,
16020 from_index,
16021 num_type_params)) {
16022 return false;
16023 }
16024 #ifdef DEBUG
16025 if (from_index > 0) {
16026 // Verify that the type arguments of the super class match, since they
16027 // depend solely on the type parameters that were just verified to
16028 // match.
16029 ASSERT(type_args.Length() >= (from_index + num_type_params));
16030 ASSERT(other_type_args.Length() >= (from_index + num_type_params));
16031 AbstractType& type_arg = AbstractType::Handle(zone);
16032 AbstractType& other_type_arg = AbstractType::Handle(zone);
16033 for (intptr_t i = 0; i < from_index; i++) {
16034 type_arg = type_args.TypeAt(i);
16035 other_type_arg = other_type_args.TypeAt(i);
16036 // Ignore bounds of bounded types.
16037 while (type_arg.IsBoundedType()) {
16038 type_arg = BoundedType::Cast(type_arg).type();
16039 }
16040 while (other_type_arg.IsBoundedType()) {
16041 other_type_arg = BoundedType::Cast(other_type_arg).type();
16042 }
16043 ASSERT(type_arg.IsEquivalent(other_type_arg, trail));
16044 }
16045 }
16046 #endif
16047 }
16048 }
16049 if (!IsFunctionType()) {
15940 return true; 16050 return true;
15941 } 16051 }
15942 const intptr_t num_type_args = cls.NumTypeArguments(); 16052 ASSERT(Type::Cast(other).IsFunctionType());
15943 const intptr_t from_index = num_type_args - num_type_params; 16053 // Equal function types must have equal signature types and equal optional
15944 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); 16054 // named arguments.
15945 const TypeArguments& other_type_args = TypeArguments::Handle( 16055 if (signature() == other_type.signature()) {
15946 zone, other_type.arguments()); 16056 return true;
15947 if (type_args.IsNull()) {
15948 // Ignore from_index.
15949 return other_type_args.IsRaw(0, num_type_args);
15950 } 16057 }
15951 if (other_type_args.IsNull()) { 16058 const Function& sig_fun = Function::Handle(zone, signature());
15952 // Ignore from_index. 16059 const Function& other_sig_fun = Function::Handle(
15953 return type_args.IsRaw(0, num_type_args); 16060 zone, other_type.signature());
15954 } 16061
15955 if (!type_args.IsSubvectorEquivalent(other_type_args, 16062 // Compare number of function parameters.
15956 from_index, 16063 const intptr_t num_fixed_params = sig_fun.num_fixed_parameters();
15957 num_type_params)) { 16064 const intptr_t other_num_fixed_params = other_sig_fun.num_fixed_parameters();
16065 if (num_fixed_params != other_num_fixed_params) {
15958 return false; 16066 return false;
15959 } 16067 }
15960 #ifdef DEBUG 16068 const intptr_t num_opt_pos_params = sig_fun.NumOptionalPositionalParameters();
15961 if (from_index > 0) { 16069 const intptr_t other_num_opt_pos_params =
15962 // Verify that the type arguments of the super class match, since they 16070 other_sig_fun.NumOptionalPositionalParameters();
15963 // depend solely on the type parameters that were just verified to match. 16071 if (num_opt_pos_params != other_num_opt_pos_params) {
15964 ASSERT(type_args.Length() >= (from_index + num_type_params)); 16072 return false;
15965 ASSERT(other_type_args.Length() >= (from_index + num_type_params)); 16073 }
15966 AbstractType& type_arg = AbstractType::Handle(zone); 16074 const intptr_t num_opt_named_params = sig_fun.NumOptionalNamedParameters();
15967 AbstractType& other_type_arg = AbstractType::Handle(zone); 16075 const intptr_t other_num_opt_named_params =
15968 for (intptr_t i = 0; i < from_index; i++) { 16076 other_sig_fun.NumOptionalNamedParameters();
15969 type_arg = type_args.TypeAt(i); 16077 if (num_opt_named_params != other_num_opt_named_params) {
15970 other_type_arg = other_type_args.TypeAt(i); 16078 return false;
15971 // Ignore bounds of bounded types. 16079 }
15972 while (type_arg.IsBoundedType()) { 16080 const intptr_t num_ignored_params = sig_fun.NumImplicitParameters();
15973 type_arg = BoundedType::Cast(type_arg).type(); 16081 const intptr_t other_num_ignored_params =
15974 } 16082 other_sig_fun.NumImplicitParameters();
15975 while (other_type_arg.IsBoundedType()) { 16083 if (num_ignored_params != other_num_ignored_params) {
15976 other_type_arg = BoundedType::Cast(other_type_arg).type(); 16084 return false;
15977 } 16085 }
15978 ASSERT(type_arg.IsEquivalent(other_type_arg, trail)); 16086 AbstractType& param_type = Type::Handle(zone);
16087 AbstractType& other_param_type = Type::Handle(zone);
16088 // Check the result type.
16089 param_type = sig_fun.result_type();
16090 other_param_type = other_sig_fun.result_type();
16091 if (!param_type.Equals(other_param_type)) {
16092 return false;
16093 }
16094 // Check the types of all parameters.
16095 const intptr_t num_params = sig_fun.NumParameters();
16096 ASSERT(other_sig_fun.NumParameters() == num_params);
16097 for (intptr_t i = 0; i < num_params; i++) {
16098 param_type = sig_fun.ParameterTypeAt(i);
16099 other_param_type = other_sig_fun.ParameterTypeAt(i);
16100 if (!param_type.Equals(other_param_type)) {
16101 return false;
15979 } 16102 }
15980 } 16103 }
15981 #endif 16104 // Check the names and types of optional named parameters.
16105 if (num_opt_named_params == 0) {
16106 return true;
16107 }
16108 for (intptr_t i = num_fixed_params; i < num_params; i++) {
16109 if (sig_fun.ParameterNameAt(i) != other_sig_fun.ParameterNameAt(i)) {
16110 return false;
16111 }
16112 }
15982 return true; 16113 return true;
15983 } 16114 }
15984 16115
15985
hausner 2016/03/21 20:59:17 Nit: keep this empty line.
regis 2016/03/21 21:07:09 Done.
15986 bool Type::IsRecursive() const { 16116 bool Type::IsRecursive() const {
15987 return TypeArguments::Handle(arguments()).IsRecursive(); 16117 return TypeArguments::Handle(arguments()).IsRecursive();
15988 } 16118 }
15989 16119
15990 16120
15991 RawAbstractType* Type::CloneUnfinalized() const { 16121 RawAbstractType* Type::CloneUnfinalized() const {
15992 ASSERT(IsResolved()); 16122 ASSERT(IsResolved());
15993 if (IsFinalized()) { 16123 if (IsFinalized()) {
15994 return raw(); 16124 return raw();
15995 } 16125 }
15996 ASSERT(!IsMalformed()); // Malformed types are finalized. 16126 ASSERT(!IsMalformed()); // Malformed types are finalized.
15997 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. 16127 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization.
15998 TypeArguments& type_args = TypeArguments::Handle(arguments()); 16128 Zone* zone = Thread::Current()->zone();
15999 type_args = type_args.CloneUnfinalized(); 16129 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16000 const Type& clone = Type::Handle( 16130 const TypeArguments& type_args_clone =
16001 Type::New(Class::Handle(type_class()), type_args, token_pos())); 16131 TypeArguments::Handle(zone, type_args.CloneUnfinalized());
16132 if (type_args_clone.raw() == type_args.raw()) {
16133 return raw();
16134 }
16135 const Type& clone = Type::Handle(zone,
16136 Type::New(Class::Handle(zone, type_class()), type_args, token_pos()));
16137 // Preserve the bound error if any.
16138 if (IsMalbounded()) {
16139 const LanguageError& bound_error = LanguageError::Handle(zone, error());
16140 clone.set_error(bound_error);
16141 }
16142 // Clone the signature if this type represents a function type.
16143 Function& fun = Function::Handle(zone, signature());
16144 if (!fun.IsNull()) {
16145 const Class& owner = Class::Handle(zone, fun.Owner());
16146 Function& fun_clone = Function::Handle(zone,
16147 Function::NewSignatureFunction(owner, TokenPosition::kNoSource));
16148 AbstractType& type = AbstractType::Handle(zone, fun.result_type());
16149 type = type.CloneUnfinalized();
16150 fun_clone.set_result_type(type);
16151 const intptr_t num_params = fun.NumParameters();
16152 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters());
16153 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(),
16154 fun.HasOptionalPositionalParameters());
16155 fun_clone.set_parameter_types(Array::Handle(Array::New(num_params,
16156 Heap::kOld)));
16157 for (intptr_t i = 0; i < num_params; i++) {
16158 type = fun.ParameterTypeAt(i);
16159 type = type.CloneUnfinalized();
16160 fun_clone.SetParameterTypeAt(i, type);
16161 }
16162 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names()));
16163 clone.set_signature(fun_clone);
16164 }
16002 clone.SetIsResolved(); 16165 clone.SetIsResolved();
16003 return clone.raw(); 16166 return clone.raw();
16004 } 16167 }
16005 16168
16006 16169
16007 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner, 16170 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner,
16008 TrailPtr trail) const { 16171 TrailPtr trail) const {
16009 ASSERT(IsFinalized()); 16172 ASSERT(IsFinalized());
16010 ASSERT(!IsMalformed()); 16173 ASSERT(!IsMalformed());
16011 if (IsInstantiated()) { 16174 if (IsInstantiated()) {
16012 return raw(); 16175 return raw();
16013 } 16176 }
16014 // We may recursively encounter a type already being cloned, because we clone 16177 // We may recursively encounter a type already being cloned, because we clone
16015 // the upper bounds of its uninstantiated type arguments in the same pass. 16178 // the upper bounds of its uninstantiated type arguments in the same pass.
16016 Type& clone = Type::Handle(); 16179 Zone* zone = Thread::Current()->zone();
16180 Type& clone = Type::Handle(zone);
16017 clone ^= OnlyBuddyInTrail(trail); 16181 clone ^= OnlyBuddyInTrail(trail);
16018 if (!clone.IsNull()) { 16182 if (!clone.IsNull()) {
16019 return clone.raw(); 16183 return clone.raw();
16020 } 16184 }
16021 const Class& type_cls = Class::Handle(type_class()); 16185 const Class& type_cls = Class::Handle(zone, type_class());
16022 clone = Type::New(type_cls, TypeArguments::Handle(), token_pos()); 16186 clone = Type::New(type_cls, TypeArguments::Handle(zone), token_pos());
16023 TypeArguments& type_args = TypeArguments::Handle(arguments()); 16187 // Preserve the bound error if any.
16188 if (IsMalbounded()) {
16189 const LanguageError& bound_error = LanguageError::Handle(zone, error());
16190 clone.set_error(bound_error);
16191 }
16192 // Clone the signature if this type represents a function type.
16193 const Function& fun = Function::Handle(zone, signature());
16194 if (!fun.IsNull()) {
16195 Function& fun_clone = Function::Handle(zone,
16196 Function::NewSignatureFunction(new_owner, TokenPosition::kNoSource));
16197 AbstractType& type = AbstractType::Handle(zone, fun.result_type());
16198 type = type.CloneUninstantiated(new_owner, trail);
16199 fun_clone.set_result_type(type);
16200 const intptr_t num_params = fun.NumParameters();
16201 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters());
16202 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(),
16203 fun.HasOptionalPositionalParameters());
16204 fun_clone.set_parameter_types(Array::Handle(Array::New(num_params,
16205 Heap::kOld)));
16206 for (intptr_t i = 0; i < num_params; i++) {
16207 type = fun.ParameterTypeAt(i);
16208 type = type.CloneUninstantiated(new_owner, trail);
16209 fun_clone.SetParameterTypeAt(i, type);
16210 }
16211 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names()));
16212 clone.set_signature(fun_clone);
16213 }
16214 TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16024 // Upper bounds of uninstantiated type arguments may form a cycle. 16215 // Upper bounds of uninstantiated type arguments may form a cycle.
16025 if (type_args.IsRecursive() || !type_args.IsInstantiated()) { 16216 if (type_args.IsRecursive() || !type_args.IsInstantiated()) {
16026 AddOnlyBuddyToTrail(&trail, clone); 16217 AddOnlyBuddyToTrail(&trail, clone);
16027 } 16218 }
16028 type_args = type_args.CloneUninstantiated(new_owner, trail); 16219 type_args = type_args.CloneUninstantiated(new_owner, trail);
16029 clone.set_arguments(type_args); 16220 clone.set_arguments(type_args);
16030 clone.SetIsFinalized(); 16221 clone.SetIsFinalized();
16031 return clone.raw(); 16222 return clone.raw();
16032 } 16223 }
16033 16224
16034 16225
16035 RawAbstractType* Type::Canonicalize(TrailPtr trail) const { 16226 RawAbstractType* Type::Canonicalize(TrailPtr trail) const {
16036 ASSERT(IsFinalized()); 16227 ASSERT(IsFinalized());
16037 if (IsCanonical() || IsMalformed()) { 16228 if (IsCanonical() || IsMalformed()) {
16038 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld()); 16229 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld());
16039 return this->raw(); 16230 return this->raw();
16040 } 16231 }
16041 Thread* thread = Thread::Current(); 16232 Thread* thread = Thread::Current();
16042 Zone* zone = thread->zone(); 16233 Zone* zone = thread->zone();
16043 Isolate* isolate = thread->isolate(); 16234 Isolate* isolate = thread->isolate();
16044 AbstractType& type = Type::Handle(zone); 16235 AbstractType& type = Type::Handle(zone);
16045 const Class& cls = Class::Handle(zone, type_class()); 16236 const Class& cls = Class::Handle(zone, type_class());
16046 ASSERT(!cls.IsTypedefClass()); // This type should be a FunctionType.
16047 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) { 16237 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) {
16048 return Object::dynamic_type().raw(); 16238 return Object::dynamic_type().raw();
16049 } 16239 }
16050 // Fast canonical lookup/registry for simple types. 16240 // Fast canonical lookup/registry for simple types.
16051 if (!cls.IsGeneric() && !cls.IsClosureClass()) { 16241 if (!cls.IsGeneric() && !cls.IsClosureClass()) {
16242 ASSERT(!IsFunctionType() || cls.IsTypedefClass());
16052 type = cls.CanonicalType(); 16243 type = cls.CanonicalType();
16053 if (type.IsNull()) { 16244 if (type.IsNull()) {
16054 ASSERT(!cls.raw()->IsVMHeapObject() || (isolate == Dart::vm_isolate())); 16245 ASSERT(!cls.raw()->IsVMHeapObject() || (isolate == Dart::vm_isolate()));
16055 // Canonicalize the type arguments of the supertype, if any. 16246 // Canonicalize the type arguments of the supertype, if any.
16056 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); 16247 TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16057 type_args = type_args.Canonicalize(trail); 16248 type_args = type_args.Canonicalize(trail);
16058 if (IsCanonical()) { 16249 if (IsCanonical()) {
16059 // Canonicalizing type_args canonicalized this type. 16250 // Canonicalizing type_args canonicalized this type.
16060 ASSERT(IsRecursive()); 16251 ASSERT(IsRecursive());
16061 return this->raw(); 16252 return this->raw();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
16105 16296
16106 // Canonicalize the type arguments. 16297 // Canonicalize the type arguments.
16107 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); 16298 TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16108 // In case the type is first canonicalized at runtime, its type argument 16299 // In case the type is first canonicalized at runtime, its type argument
16109 // vector may be longer than necessary. This is not an issue. 16300 // vector may be longer than necessary. This is not an issue.
16110 ASSERT(type_args.IsNull() || (type_args.Length() >= cls.NumTypeArguments())); 16301 ASSERT(type_args.IsNull() || (type_args.Length() >= cls.NumTypeArguments()));
16111 type_args = type_args.Canonicalize(trail); 16302 type_args = type_args.Canonicalize(trail);
16112 if (IsCanonical()) { 16303 if (IsCanonical()) {
16113 // Canonicalizing type_args canonicalized this type as a side effect. 16304 // Canonicalizing type_args canonicalized this type as a side effect.
16114 ASSERT(IsRecursive()); 16305 ASSERT(IsRecursive());
16306 // Cycles via typedefs are detected and disallowed, but a function type can
16307 // be recursive due to a cycle in its type arguments.
16115 return this->raw(); 16308 return this->raw();
16116 } 16309 }
16117 set_arguments(type_args); 16310 set_arguments(type_args);
16118 ASSERT(type_args.IsNull() || type_args.IsOld()); 16311 ASSERT(type_args.IsNull() || type_args.IsOld());
16119 16312
16313 // In case of a function type, replace the actual function by a signature
16314 // function.
16315 if (IsFunctionType()) {
16316 const Function& fun = Function::Handle(zone, signature());
16317 if (!fun.IsSignatureFunction()) {
16318 Function& sig_fun = Function::Handle(zone,
16319 Function::NewSignatureFunction(cls, TokenPosition::kNoSource));
16320 type = fun.result_type();
16321 type = type.Canonicalize(trail);
16322 sig_fun.set_result_type(type);
16323 const intptr_t num_params = fun.NumParameters();
16324 sig_fun.set_num_fixed_parameters(fun.num_fixed_parameters());
16325 sig_fun.SetNumOptionalParameters(fun.NumOptionalParameters(),
16326 fun.HasOptionalPositionalParameters());
16327 sig_fun.set_parameter_types(Array::Handle(Array::New(num_params,
16328 Heap::kOld)));
16329 for (intptr_t i = 0; i < num_params; i++) {
16330 type = fun.ParameterTypeAt(i);
16331 type = type.Canonicalize(trail);
16332 sig_fun.SetParameterTypeAt(i, type);
16333 }
16334 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names()));
16335 set_signature(sig_fun);
16336 }
16337 }
16120 return cls.LookupOrAddCanonicalType(*this, index); 16338 return cls.LookupOrAddCanonicalType(*this, index);
16121 } 16339 }
16122 16340
16123 16341
16124 RawString* Type::EnumerateURIs() const { 16342 RawString* Type::EnumerateURIs() const {
16125 if (IsDynamicType() || IsVoidType()) { 16343 if (IsDynamicType() || IsVoidType()) {
16126 return Symbols::Empty().raw(); 16344 return Symbols::Empty().raw();
16127 } 16345 }
16128 Zone* zone = Thread::Current()->zone(); 16346 Zone* zone = Thread::Current()->zone();
16129 GrowableHandlePtrArray<const String> pieces(zone, 6); 16347 GrowableHandlePtrArray<const String> pieces(zone, 6);
16130 const Class& cls = Class::Handle(zone, type_class()); 16348 if (IsFunctionType()) {
16131 pieces.Add(Symbols::TwoSpaces()); 16349 // The scope class and type arguments do not appear explicitly in the user
16132 pieces.Add(String::Handle(zone, cls.UserVisibleName())); 16350 // visible name. The type arguments were used to instantiate the function
16133 pieces.Add(Symbols::SpaceIsFromSpace()); 16351 // type prior to this call.
16134 const Library& library = Library::Handle(zone, cls.library()); 16352 const Function& sig_fun = Function::Handle(zone, signature());
16135 pieces.Add(String::Handle(zone, library.url())); 16353 AbstractType& type = AbstractType::Handle(zone);
16136 pieces.Add(Symbols::NewLine()); 16354 const intptr_t num_params = sig_fun.NumParameters();
16137 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); 16355 GrowableHandlePtrArray<const String> pieces(zone, num_params + 1);
16138 pieces.Add(String::Handle(zone, type_args.EnumerateURIs())); 16356 for (intptr_t i = 0; i < num_params; i++) {
16357 type = sig_fun.ParameterTypeAt(i);
16358 pieces.Add(String::Handle(zone, type.EnumerateURIs()));
16359 }
16360 // Handle result type last, since it appears last in the user visible name.
16361 type = sig_fun.result_type();
16362 pieces.Add(String::Handle(zone, type.EnumerateURIs()));
16363 } else {
16364 const Class& cls = Class::Handle(zone, type_class());
16365 pieces.Add(Symbols::TwoSpaces());
16366 pieces.Add(String::Handle(zone, cls.UserVisibleName()));
16367 pieces.Add(Symbols::SpaceIsFromSpace());
16368 const Library& library = Library::Handle(zone, cls.library());
16369 pieces.Add(String::Handle(zone, library.url()));
16370 pieces.Add(Symbols::NewLine());
16371 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16372 pieces.Add(String::Handle(zone, type_args.EnumerateURIs()));
16373 }
16139 return Symbols::FromConcatAll(pieces); 16374 return Symbols::FromConcatAll(pieces);
16140 } 16375 }
16141 16376
16142 16377
16143 intptr_t Type::Hash() const { 16378 intptr_t Type::Hash() const {
16144 ASSERT(IsFinalized()); 16379 ASSERT(IsFinalized());
16145 uint32_t result = 1; 16380 uint32_t result = 1;
16146 if (IsMalformed()) return result; 16381 if (IsMalformed()) return result;
16147 result = CombineHashes(result, Class::Handle(type_class()).id()); 16382 result = CombineHashes(result, Class::Handle(type_class()).id());
16148 result = CombineHashes(result, TypeArguments::Handle(arguments()).Hash()); 16383 result = CombineHashes(result, TypeArguments::Handle(arguments()).Hash());
16384 if (IsFunctionType()) {
16385 const Function& sig_fun = Function::Handle(signature());
16386 AbstractType& type = AbstractType::Handle(sig_fun.result_type());
16387 result = CombineHashes(result, type.Hash());
16388 result = CombineHashes(result, sig_fun.NumOptionalPositionalParameters());
16389 const intptr_t num_params = sig_fun.NumParameters();
16390 for (intptr_t i = 0; i < num_params; i++) {
16391 type = sig_fun.ParameterTypeAt(i);
16392 result = CombineHashes(result, type.Hash());
16393 }
16394 if (sig_fun.NumOptionalNamedParameters() > 0) {
16395 String& param_name = String::Handle();
16396 for (intptr_t i = sig_fun.num_fixed_parameters(); i < num_params; i++) {
16397 param_name = sig_fun.ParameterNameAt(i);
16398 result = CombineHashes(result, param_name.Hash());
16399 }
16400 }
16401 }
16149 return FinalizeHash(result); 16402 return FinalizeHash(result);
16150 } 16403 }
16151 16404
16152 16405
16153 void Type::set_type_class(const Object& value) const { 16406 void Type::set_type_class(const Object& value) const {
16154 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass())); 16407 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass()));
16155 StorePointer(&raw_ptr()->type_class_, value.raw()); 16408 StorePointer(&raw_ptr()->type_class_, value.raw());
16156 } 16409 }
16157 16410
16158 16411
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
16190 16443
16191 16444
16192 void Type::set_type_state(int8_t state) const { 16445 void Type::set_type_state(int8_t state) const {
16193 ASSERT((state >= RawType::kAllocated) && 16446 ASSERT((state >= RawType::kAllocated) &&
16194 (state <= RawType::kFinalizedUninstantiated)); 16447 (state <= RawType::kFinalizedUninstantiated));
16195 StoreNonPointer(&raw_ptr()->type_state_, state); 16448 StoreNonPointer(&raw_ptr()->type_state_, state);
16196 } 16449 }
16197 16450
16198 16451
16199 const char* Type::ToCString() const { 16452 const char* Type::ToCString() const {
16453 Zone* zone = Thread::Current()->zone();
16200 const char* unresolved = IsResolved() ? "" : "Unresolved "; 16454 const char* unresolved = IsResolved() ? "" : "Unresolved ";
16201 const TypeArguments& type_arguments = TypeArguments::Handle(arguments()); 16455 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16456 const char* args_cstr = type_args.IsNull() ? "null" : type_args.ToCString();
16457 Class& cls = Class::Handle(zone);
16202 const char* class_name; 16458 const char* class_name;
16203 if (HasResolvedTypeClass()) { 16459 if (HasResolvedTypeClass()) {
16204 class_name = String::Handle( 16460 cls = type_class();
16205 Class::Handle(type_class()).Name()).ToCString(); 16461 class_name = String::Handle(zone, cls.Name()).ToCString();
16206 } else { 16462 } else {
16207 class_name = UnresolvedClass::Handle(unresolved_class()).ToCString(); 16463 class_name = UnresolvedClass::Handle(zone, unresolved_class()).ToCString();
16208 } 16464 }
16209 if (type_arguments.IsNull()) { 16465 if (IsFunctionType()) {
16210 return OS::SCreate(Thread::Current()->zone(), 16466 const Function& sig_fun = Function::Handle(zone, signature());
16211 "%sType: class '%s'", unresolved, class_name); 16467 const String& sig = IsFinalized() ?
16468 String::Handle(zone, sig_fun.InstantiatedSignatureFrom(type_args,
16469 kInternalName)) :
16470 String::Handle(zone, sig_fun.Signature());
16471 if (cls.IsClosureClass()) {
16472 ASSERT(type_args.IsNull());
16473 return OS::SCreate(zone, "%sFunction Type: %s",
16474 unresolved, sig.ToCString());
16475 }
16476 return OS::SCreate(zone, "%s Function Type: %s (class: %s, args: %s)",
16477 unresolved,
16478 sig.ToCString(),
16479 class_name,
16480 args_cstr);
16481 }
16482 if (type_args.IsNull()) {
16483 return OS::SCreate(zone, "%sType: class '%s'", unresolved, class_name);
16212 } else if (IsResolved() && IsFinalized() && IsRecursive()) { 16484 } else if (IsResolved() && IsFinalized() && IsRecursive()) {
16213 const intptr_t hash = Hash(); 16485 const intptr_t hash = Hash();
16214 const char* args_cstr = TypeArguments::Handle(arguments()).ToCString(); 16486 return OS::SCreate(zone, "Type: (@%p H%" Px ") class '%s', args:[%s]",
16215 return OS::SCreate(Thread::Current()->zone(), 16487 raw(), hash, class_name, args_cstr);
16216 "Type: (@%p H%" Px ") class '%s', args:[%s]",
16217 raw(), hash, class_name, args_cstr);
16218 } else { 16488 } else {
16219 const char* args_cstr = TypeArguments::Handle(arguments()).ToCString(); 16489 return OS::SCreate(zone, "%sType: class '%s', args:[%s]",
16220 return OS::SCreate(Thread::Current()->zone(), 16490 unresolved, class_name, args_cstr);
16221 "%sType: class '%s', args:[%s]", unresolved, class_name, args_cstr);
16222 } 16491 }
16223 } 16492 }
16224 16493
16225 16494
16226 void FunctionType::SetIsFinalized() const {
16227 ASSERT(!IsFinalized());
16228 if (IsInstantiated()) {
16229 set_type_state(RawFunctionType::kFinalizedInstantiated);
16230 } else {
16231 set_type_state(RawFunctionType::kFinalizedUninstantiated);
16232 }
16233 }
16234
16235
16236 void FunctionType::ResetIsFinalized() const {
16237 ASSERT(IsFinalized());
16238 set_type_state(RawFunctionType::kBeingFinalized);
16239 SetIsFinalized();
16240 }
16241
16242
16243 void FunctionType::SetIsBeingFinalized() const {
16244 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized());
16245 set_type_state(RawFunctionType::kBeingFinalized);
16246 }
16247
16248
16249 bool FunctionType::IsMalformed() const {
16250 if (raw_ptr()->error_ == LanguageError::null()) {
16251 return false;
16252 }
16253 const LanguageError& type_error = LanguageError::Handle(error());
16254 return type_error.kind() == Report::kMalformedType;
16255 }
16256
16257
16258 bool FunctionType::IsMalbounded() const {
16259 if (!Isolate::Current()->type_checks()) {
16260 return false;
16261 }
16262 if (raw_ptr()->error_ == LanguageError::null()) {
16263 return false;
16264 }
16265 const LanguageError& type_error = LanguageError::Handle(error());
16266 return type_error.kind() == Report::kMalboundedType;
16267 }
16268
16269
16270 bool FunctionType::IsMalformedOrMalbounded() const {
16271 if (raw_ptr()->error_ == LanguageError::null()) {
16272 return false;
16273 }
16274 const LanguageError& type_error = LanguageError::Handle(error());
16275 if (type_error.kind() == Report::kMalformedType) {
16276 return true;
16277 }
16278 ASSERT(type_error.kind() == Report::kMalboundedType);
16279 return Isolate::Current()->type_checks();
16280 }
16281
16282
16283 void FunctionType::set_error(const LanguageError& value) const {
16284 StorePointer(&raw_ptr()->error_, value.raw());
16285 }
16286
16287
16288 void FunctionType::SetIsResolved() const {
16289 ASSERT(!IsResolved());
16290 set_type_state(RawFunctionType::kResolved);
16291 }
16292
16293
16294 bool FunctionType::IsInstantiated(TrailPtr trail) const {
16295 if (raw_ptr()->type_state_ == RawFunctionType::kFinalizedInstantiated) {
16296 return true;
16297 }
16298 if (raw_ptr()->type_state_ == RawFunctionType::kFinalizedUninstantiated) {
16299 return false;
16300 }
16301 if (arguments() == TypeArguments::null()) {
16302 return true;
16303 }
16304 const Class& scope_cls = Class::Handle(scope_class());
16305 if (!scope_cls.IsGeneric()) {
16306 ASSERT(scope_cls.IsClosureClass() || scope_cls.IsTypedefClass());
16307 ASSERT(arguments() == TypeArguments::null());
16308 return true;
16309 }
16310 const TypeArguments& type_arguments = TypeArguments::Handle(arguments());
16311 const intptr_t num_type_args = scope_cls.NumTypeArguments();
16312 const intptr_t num_type_params = scope_cls.NumTypeParameters();
16313 // The vector may be longer than necessary. An empty vector is handled above.
16314 ASSERT(type_arguments.Length() >= num_type_args);
16315 return
16316 (num_type_params == 0) ||
16317 type_arguments.IsSubvectorInstantiated(num_type_args - num_type_params,
16318 num_type_params);
16319 }
16320
16321
16322 RawAbstractType* FunctionType::InstantiateFrom(
16323 const TypeArguments& instantiator_type_arguments,
16324 Error* bound_error,
16325 TrailPtr instantiation_trail,
16326 TrailPtr bound_trail,
16327 Heap::Space space) const {
16328 Zone* zone = Thread::Current()->zone();
16329 ASSERT(IsFinalized() || IsBeingFinalized());
16330 ASSERT(!IsInstantiated());
16331 ASSERT(!IsMalformed()); // FunctionType cannot be malformed.
16332 // Instantiating this type with its own type arguments as instantiator can
16333 // occur during finalization and bounds checking. Return the type unchanged.
16334 if (arguments() == instantiator_type_arguments.raw()) {
16335 return raw();
16336 }
16337 // Note that the scope class has to be resolved at this time, but not
16338 // necessarily finalized yet. We may be checking bounds at compile time or
16339 // finalizing the type argument vector of a recursive type.
16340 const Class& cls = Class::Handle(zone, scope_class());
16341 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments());
16342 ASSERT(type_arguments.Length() == cls.NumTypeArguments());
16343 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments,
16344 bound_error,
16345 instantiation_trail,
16346 bound_trail,
16347 space);
16348 // This uninstantiated type is not modified, as it can be instantiated
16349 // with different instantiators. Allocate a new instantiated version of it.
16350 const FunctionType& instantiated_type = FunctionType::Handle(zone,
16351 FunctionType::New(cls,
16352 type_arguments,
16353 Function::Handle(zone, signature()),
16354 token_pos(),
16355 space));
16356 if (IsFinalized()) {
16357 instantiated_type.SetIsFinalized();
16358 } else {
16359 instantiated_type.SetIsResolved();
16360 }
16361 // Canonicalization is not part of instantiation.
16362 return instantiated_type.raw();
16363 }
16364
16365
16366 bool FunctionType::IsEquivalent(const Instance& other, TrailPtr trail) const {
16367 ASSERT(!IsNull());
16368 if (raw() == other.raw()) {
16369 return true;
16370 }
16371 if (!other.IsFunctionType()) {
16372 return false;
16373 }
16374 const FunctionType& other_type = FunctionType::Cast(other);
16375 ASSERT(IsResolved() && other_type.IsResolved());
16376 if (IsMalformed() || other_type.IsMalformed()) {
16377 return false;
16378 }
16379 if (scope_class() != other_type.scope_class()) {
16380 return false;
16381 }
16382 if ((arguments() == other_type.arguments()) &&
16383 (signature() == other_type.signature())) {
16384 return true;
16385 }
16386 if (!IsFinalized() || !other_type.IsFinalized()) {
16387 return false;
16388 }
16389
16390 // We do not instantiate the types of the signature. This happens on demand
16391 // at runtime during a type test.
16392 // Therefore, equal function types must have equal type arguments.
16393 Thread* thread = Thread::Current();
16394 Zone* zone = thread->zone();
16395 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16396 const TypeArguments& other_type_args = TypeArguments::Handle(
16397 zone, other_type.arguments());
16398 if (!type_args.Equals(other_type_args)) {
16399 return false;
16400 }
16401
16402 // Type arguments are equal.
16403 // Equal function types must have equal signature types and equal optional
16404 // named arguments.
16405 if (signature() == other_type.signature()) {
16406 return true;
16407 }
16408 const Function& sig_fun = Function::Handle(zone, signature());
16409 const Function& other_sig_fun = Function::Handle(
16410 zone, other_type.signature());
16411
16412 // Compare number of function parameters.
16413 const intptr_t num_fixed_params = sig_fun.num_fixed_parameters();
16414 const intptr_t other_num_fixed_params = other_sig_fun.num_fixed_parameters();
16415 if (num_fixed_params != other_num_fixed_params) {
16416 return false;
16417 }
16418 const intptr_t num_opt_pos_params = sig_fun.NumOptionalPositionalParameters();
16419 const intptr_t other_num_opt_pos_params =
16420 other_sig_fun.NumOptionalPositionalParameters();
16421 if (num_opt_pos_params != other_num_opt_pos_params) {
16422 return false;
16423 }
16424 const intptr_t num_opt_named_params = sig_fun.NumOptionalNamedParameters();
16425 const intptr_t other_num_opt_named_params =
16426 other_sig_fun.NumOptionalNamedParameters();
16427 if (num_opt_named_params != other_num_opt_named_params) {
16428 return false;
16429 }
16430 const intptr_t num_ignored_params = sig_fun.NumImplicitParameters();
16431 const intptr_t other_num_ignored_params =
16432 other_sig_fun.NumImplicitParameters();
16433 if (num_ignored_params != other_num_ignored_params) {
16434 return false;
16435 }
16436 AbstractType& param_type = Type::Handle(zone);
16437 AbstractType& other_param_type = Type::Handle(zone);
16438 // Check the result type.
16439 param_type = sig_fun.result_type();
16440 other_param_type = other_sig_fun.result_type();
16441 if (!param_type.Equals(other_param_type)) {
16442 return false;
16443 }
16444 // Check the types of all parameters.
16445 const intptr_t num_params = sig_fun.NumParameters();
16446 ASSERT(other_sig_fun.NumParameters() == num_params);
16447 for (intptr_t i = 0; i < num_params; i++) {
16448 param_type = sig_fun.ParameterTypeAt(i);
16449 other_param_type = other_sig_fun.ParameterTypeAt(i);
16450 if (!param_type.Equals(other_param_type)) {
16451 return false;
16452 }
16453 }
16454 // Check the names and types of optional named parameters.
16455 if (num_opt_named_params == 0) {
16456 return true;
16457 }
16458 for (intptr_t i = num_fixed_params; i < num_params; i++) {
16459 if (sig_fun.ParameterNameAt(i) != other_sig_fun.ParameterNameAt(i)) {
16460 return false;
16461 }
16462 }
16463 return true;
16464 }
16465
16466
16467 bool FunctionType::IsRecursive() const {
16468 return TypeArguments::Handle(arguments()).IsRecursive();
16469 }
16470
16471
16472 RawAbstractType* FunctionType::CloneUnfinalized() const {
16473 ASSERT(IsResolved());
16474 if (IsFinalized()) {
16475 return raw();
16476 }
16477 ASSERT(!IsMalformed()); // Malformed types are finalized.
16478 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization.
16479 TypeArguments& type_args = TypeArguments::Handle(arguments());
16480 type_args = type_args.CloneUnfinalized();
16481 const FunctionType& clone = FunctionType::Handle(
16482 FunctionType::New(Class::Handle(scope_class()),
16483 type_args,
16484 Function::Handle(signature()),
16485 token_pos()));
16486 clone.SetIsResolved();
16487 return clone.raw();
16488 }
16489
16490
16491 RawAbstractType* FunctionType::CloneUninstantiated(const Class& new_owner,
16492 TrailPtr trail) const {
16493 ASSERT(IsFinalized());
16494 ASSERT(!IsMalformed());
16495 if (IsInstantiated()) {
16496 return raw();
16497 }
16498 // We may recursively encounter a type already being cloned, because we clone
16499 // the upper bounds of its uninstantiated type arguments in the same pass.
16500 FunctionType& clone = FunctionType::Handle();
16501 clone ^= OnlyBuddyInTrail(trail);
16502 if (!clone.IsNull()) {
16503 return clone.raw();
16504 }
16505 clone = FunctionType::New(Class::Handle(scope_class()),
16506 TypeArguments::Handle(),
16507 Function::Handle(signature()),
16508 token_pos());
16509 TypeArguments& type_args = TypeArguments::Handle(arguments());
16510 // Upper bounds of uninstantiated type arguments may form a cycle.
16511 if (type_args.IsRecursive() || !type_args.IsInstantiated()) {
16512 AddOnlyBuddyToTrail(&trail, clone);
16513 }
16514 type_args = type_args.CloneUninstantiated(new_owner, trail);
16515 clone.set_arguments(type_args);
16516 clone.SetIsFinalized();
16517 return clone.raw();
16518 }
16519
16520
16521 RawAbstractType* FunctionType::Canonicalize(TrailPtr trail) const {
16522 ASSERT(IsFinalized());
16523 if (IsCanonical() || IsMalformed()) {
16524 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld());
16525 return this->raw();
16526 }
16527 Thread* thread = Thread::Current();
16528 Zone* zone = thread->zone();
16529 AbstractType& type = Type::Handle(zone);
16530 const Class& scope_cls = Class::Handle(zone, type_class());
16531 Array& canonical_types = Array::Handle(zone);
16532 canonical_types ^= scope_cls.canonical_types();
16533 if (canonical_types.IsNull()) {
16534 canonical_types = empty_array().raw();
16535 }
16536 intptr_t length = canonical_types.Length();
16537 // Linear search to see whether this type is already present in the
16538 // list of canonicalized types.
16539 // TODO(asiva): Try to re-factor this lookup code to make sharing
16540 // easy between the 4 versions of this loop.
16541 intptr_t index = 1; // Slot 0 is reserved for CanonicalType().
16542 while (index < length) {
16543 type ^= canonical_types.At(index);
16544 if (type.IsNull()) {
16545 break;
16546 }
16547 ASSERT(type.IsFinalized());
16548 if (this->Equals(type)) {
16549 ASSERT(type.IsCanonical());
16550 return type.raw();
16551 }
16552 index++;
16553 }
16554 // The type was not found in the table. It is not canonical yet.
16555
16556 // Canonicalize the type arguments.
16557 TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16558 // In case the type is first canonicalized at runtime, its type argument
16559 // vector may be longer than necessary. This is not an issue.
16560 ASSERT(type_args.IsNull() ||
16561 (type_args.Length() >= scope_cls.NumTypeArguments()));
16562 type_args = type_args.Canonicalize(trail);
16563 if (IsCanonical()) {
16564 // Canonicalizing type_args canonicalized this type as a side effect.
16565 ASSERT(IsRecursive());
16566 // Cycles via typedefs are detected and disallowed, but a function type can
16567 // be recursive due to a cycle in its type arguments.
16568 return this->raw();
16569 }
16570 set_arguments(type_args);
16571
16572 // Replace the actual function by a signature function.
16573 const Function& fun = Function::Handle(zone, signature());
16574 if (!fun.IsSignatureFunction()) {
16575 Function& sig_fun = Function::Handle(zone,
16576 Function::NewSignatureFunction(scope_cls, TokenPosition::kNoSource));
16577 type = fun.result_type();
16578 type = type.Canonicalize(trail);
16579 sig_fun.set_result_type(type);
16580 const intptr_t num_params = fun.NumParameters();
16581 sig_fun.set_num_fixed_parameters(fun.num_fixed_parameters());
16582 sig_fun.SetNumOptionalParameters(fun.NumOptionalParameters(),
16583 fun.HasOptionalPositionalParameters());
16584 sig_fun.set_parameter_types(Array::Handle(Array::New(num_params,
16585 Heap::kOld)));
16586 for (intptr_t i = 0; i < num_params; i++) {
16587 type = fun.ParameterTypeAt(i);
16588 type = type.Canonicalize(trail);
16589 sig_fun.SetParameterTypeAt(i, type);
16590 }
16591 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names()));
16592 set_signature(sig_fun);
16593 }
16594 ASSERT(type_args.IsNull() || type_args.IsOld());
16595
16596 return scope_cls.LookupOrAddCanonicalType(*this, index);
16597 }
16598
16599
16600 RawString* FunctionType::EnumerateURIs() const {
16601 Zone* zone = Thread::Current()->zone();
16602 // The scope class and type arguments do not appear explicitly in the user
16603 // visible name. The type arguments were used to instantiate the function type
16604 // prior to this call.
16605 const Function& sig_fun = Function::Handle(zone, signature());
16606 AbstractType& type = AbstractType::Handle(zone);
16607 const intptr_t num_params = sig_fun.NumParameters();
16608 GrowableHandlePtrArray<const String> pieces(zone, num_params + 1);
16609 for (intptr_t i = 0; i < num_params; i++) {
16610 type = sig_fun.ParameterTypeAt(i);
16611 pieces.Add(String::Handle(zone, type.EnumerateURIs()));
16612 }
16613 // Handle result type last, since it appears last in the user visible name.
16614 type = sig_fun.result_type();
16615 pieces.Add(String::Handle(zone, type.EnumerateURIs()));
16616 return Symbols::FromConcatAll(pieces);
16617 }
16618
16619
16620 intptr_t FunctionType::Hash() const {
16621 ASSERT(IsFinalized());
16622 uint32_t result = 1;
16623 if (IsMalformed()) return result;
16624 result = CombineHashes(result, Class::Handle(scope_class()).id());
16625 result = CombineHashes(result, TypeArguments::Handle(arguments()).Hash());
16626 const Function& sig_fun = Function::Handle(signature());
16627 AbstractType& type = AbstractType::Handle(sig_fun.result_type());
16628 result = CombineHashes(result, type.Hash());
16629 result = CombineHashes(result, sig_fun.NumOptionalPositionalParameters());
16630 const intptr_t num_params = sig_fun.NumParameters();
16631 for (intptr_t i = 0; i < num_params; i++) {
16632 type = sig_fun.ParameterTypeAt(i);
16633 result = CombineHashes(result, type.Hash());
16634 }
16635 if (sig_fun.NumOptionalNamedParameters() > 0) {
16636 String& param_name = String::Handle();
16637 for (intptr_t i = sig_fun.num_fixed_parameters(); i < num_params; i++) {
16638 param_name = sig_fun.ParameterNameAt(i);
16639 result = CombineHashes(result, param_name.Hash());
16640 }
16641 }
16642 return FinalizeHash(result);
16643 }
16644
16645
16646 void FunctionType::set_scope_class(const Class& value) const {
16647 ASSERT(!value.IsNull());
16648 StorePointer(&raw_ptr()->scope_class_, value.raw());
16649 }
16650
16651
16652 void FunctionType::set_arguments(const TypeArguments& value) const {
16653 ASSERT(!IsCanonical());
16654 StorePointer(&raw_ptr()->arguments_, value.raw());
16655 }
16656
16657
16658 void FunctionType::set_signature(const Function& value) const {
16659 StorePointer(&raw_ptr()->signature_, value.raw());
16660 }
16661
16662
16663 RawFunctionType* FunctionType::New(Heap::Space space) {
16664 RawObject* raw = Object::Allocate(FunctionType::kClassId,
16665 FunctionType::InstanceSize(),
16666 space);
16667 return reinterpret_cast<RawFunctionType*>(raw);
16668 }
16669
16670
16671 RawFunctionType* FunctionType::New(const Class& clazz,
16672 const TypeArguments& arguments,
16673 const Function& signature,
16674 TokenPosition token_pos,
16675 Heap::Space space) {
16676 const FunctionType& result = FunctionType::Handle(FunctionType::New(space));
16677 result.set_scope_class(clazz);
16678 result.set_arguments(arguments);
16679 result.set_signature(signature);
16680 result.set_token_pos(token_pos);
16681 result.StoreNonPointer(&result.raw_ptr()->type_state_,
16682 RawFunctionType::kAllocated);
16683 return result.raw();
16684 }
16685
16686
16687 void FunctionType::set_token_pos(TokenPosition token_pos) const {
16688 ASSERT(!token_pos.IsClassifying());
16689 StoreNonPointer(&raw_ptr()->token_pos_, token_pos);
16690 }
16691
16692
16693 void FunctionType::set_type_state(int8_t state) const {
16694 ASSERT((state >= RawFunctionType::kAllocated) &&
16695 (state <= RawFunctionType::kFinalizedUninstantiated));
16696 StoreNonPointer(&raw_ptr()->type_state_, state);
16697 }
16698
16699
16700 const char* FunctionType::ToCString() const {
16701 const char* unresolved = IsResolved() ? "" : "Unresolved ";
16702 const Class& scope_cls = Class::Handle(scope_class());
16703 const TypeArguments& type_arguments = TypeArguments::Handle(arguments());
16704 const Function& signature_function = Function::Handle(signature());
16705 const String& signature_string = IsFinalized() ?
16706 String::Handle(
16707 signature_function.InstantiatedSignatureFrom(type_arguments,
16708 kInternalName)) :
16709 String::Handle(signature_function.Signature());
16710 if (scope_cls.IsClosureClass()) {
16711 ASSERT(arguments() == TypeArguments::null());
16712 return OS::SCreate(
16713 Thread::Current()->zone(),
16714 "%sFunctionType: %s", unresolved, signature_string.ToCString());
16715 }
16716 const char* class_name = String::Handle(scope_cls.Name()).ToCString();
16717 const char* args_cstr =
16718 type_arguments.IsNull() ? "null" : type_arguments.ToCString();
16719 return OS::SCreate(
16720 Thread::Current()->zone(),
16721 "%s FunctionType: %s (scope_cls: %s, args: %s)",
16722 unresolved,
16723 signature_string.ToCString(),
16724 class_name,
16725 args_cstr);
16726 }
16727
16728
16729 bool TypeRef::IsInstantiated(TrailPtr trail) const { 16495 bool TypeRef::IsInstantiated(TrailPtr trail) const {
16730 if (TestAndAddToTrail(&trail)) { 16496 if (TestAndAddToTrail(&trail)) {
16731 return true; 16497 return true;
16732 } 16498 }
16733 return AbstractType::Handle(type()).IsInstantiated(trail); 16499 return AbstractType::Handle(type()).IsInstantiated(trail);
16734 } 16500 }
16735 16501
16736 16502
16737 bool TypeRef::IsEquivalent(const Instance& other, TrailPtr trail) const { 16503 bool TypeRef::IsEquivalent(const Instance& other, TrailPtr trail) const {
16738 if (raw() == other.raw()) { 16504 if (raw() == other.raw()) {
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
17290 } 17056 }
17291 } 17057 }
17292 return instantiated_bounded_type.raw(); 17058 return instantiated_bounded_type.raw();
17293 } 17059 }
17294 17060
17295 17061
17296 RawAbstractType* BoundedType::CloneUnfinalized() const { 17062 RawAbstractType* BoundedType::CloneUnfinalized() const {
17297 if (IsFinalized()) { 17063 if (IsFinalized()) {
17298 return raw(); 17064 return raw();
17299 } 17065 }
17300 AbstractType& bounded_type = AbstractType::Handle(type()); 17066 const AbstractType& bounded_type = AbstractType::Handle(type());
17301 17067 const AbstractType& bounded_type_clone =
17302 bounded_type = bounded_type.CloneUnfinalized(); 17068 AbstractType::Handle(bounded_type.CloneUnfinalized());
17069 if (bounded_type_clone.raw() == bounded_type.raw()) {
17070 return raw();
17071 }
17303 // No need to clone bound or type parameter, as they are not part of the 17072 // No need to clone bound or type parameter, as they are not part of the
17304 // finalization state of this bounded type. 17073 // finalization state of this bounded type.
17305 return BoundedType::New(bounded_type, 17074 return BoundedType::New(bounded_type,
17306 AbstractType::Handle(bound()), 17075 AbstractType::Handle(bound()),
17307 TypeParameter::Handle(type_parameter())); 17076 TypeParameter::Handle(type_parameter()));
17308 } 17077 }
17309 17078
17310 17079
17311 RawAbstractType* BoundedType::CloneUninstantiated( 17080 RawAbstractType* BoundedType::CloneUninstantiated(
17312 const Class& new_owner, TrailPtr trail) const { 17081 const Class& new_owner, TrailPtr trail) const {
(...skipping 4648 matching lines...) Expand 10 before | Expand all | Expand 10 after
21961 return UserTag::null(); 21730 return UserTag::null();
21962 } 21731 }
21963 21732
21964 21733
21965 const char* UserTag::ToCString() const { 21734 const char* UserTag::ToCString() const {
21966 const String& tag_label = String::Handle(label()); 21735 const String& tag_label = String::Handle(label());
21967 return tag_label.ToCString(); 21736 return tag_label.ToCString();
21968 } 21737 }
21969 21738
21970 } // namespace dart 21739 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698