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

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

Issue 1584223006: Remove signature classes from the VM. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: sync Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('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 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 // canonical_type_arguments_ are Smi terminated. 1115 // canonical_type_arguments_ are Smi terminated.
1116 // Last element contains the count of used slots. 1116 // Last element contains the count of used slots.
1117 const intptr_t kInitialCanonicalTypeArgumentsSize = 4; 1117 const intptr_t kInitialCanonicalTypeArgumentsSize = 4;
1118 array = Array::New(kInitialCanonicalTypeArgumentsSize + 1); 1118 array = Array::New(kInitialCanonicalTypeArgumentsSize + 1);
1119 array.SetAt(kInitialCanonicalTypeArgumentsSize, 1119 array.SetAt(kInitialCanonicalTypeArgumentsSize,
1120 Smi::Handle(zone, Smi::New(0))); 1120 Smi::Handle(zone, Smi::New(0)));
1121 object_store->set_canonical_type_arguments(array); 1121 object_store->set_canonical_type_arguments(array);
1122 1122
1123 // Setup type class early in the process. 1123 // Setup type class early in the process.
1124 const Class& type_cls = Class::Handle(zone, Class::New<Type>()); 1124 const Class& type_cls = Class::Handle(zone, Class::New<Type>());
1125 const Class& function_type_cls = Class::Handle(zone,
1126 Class::New<FunctionType>());
1125 const Class& type_ref_cls = Class::Handle(zone, Class::New<TypeRef>()); 1127 const Class& type_ref_cls = Class::Handle(zone, Class::New<TypeRef>());
1126 const Class& type_parameter_cls = Class::Handle(zone, 1128 const Class& type_parameter_cls = Class::Handle(zone,
1127 Class::New<TypeParameter>()); 1129 Class::New<TypeParameter>());
1128 const Class& bounded_type_cls = Class::Handle(zone, 1130 const Class& bounded_type_cls = Class::Handle(zone,
1129 Class::New<BoundedType>()); 1131 Class::New<BoundedType>());
1130 const Class& mixin_app_type_cls = Class::Handle(zone, 1132 const Class& mixin_app_type_cls = Class::Handle(zone,
1131 Class::New<MixinAppType>()); 1133 Class::New<MixinAppType>());
1132 const Class& library_prefix_cls = Class::Handle(zone, 1134 const Class& library_prefix_cls = Class::Handle(zone,
1133 Class::New<LibraryPrefix>()); 1135 Class::New<LibraryPrefix>());
1134 1136
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 RegisterClass(cls, Symbols::Null(), core_lib); 1279 RegisterClass(cls, Symbols::Null(), core_lib);
1278 pending_classes.Add(cls); 1280 pending_classes.Add(cls);
1279 1281
1280 ASSERT(!library_prefix_cls.IsNull()); 1282 ASSERT(!library_prefix_cls.IsNull());
1281 RegisterPrivateClass(library_prefix_cls, Symbols::_LibraryPrefix(), core_lib); 1283 RegisterPrivateClass(library_prefix_cls, Symbols::_LibraryPrefix(), core_lib);
1282 pending_classes.Add(library_prefix_cls); 1284 pending_classes.Add(library_prefix_cls);
1283 1285
1284 RegisterPrivateClass(type_cls, Symbols::Type(), core_lib); 1286 RegisterPrivateClass(type_cls, Symbols::Type(), core_lib);
1285 pending_classes.Add(type_cls); 1287 pending_classes.Add(type_cls);
1286 1288
1289 RegisterPrivateClass(function_type_cls, Symbols::FunctionType(), core_lib);
1290 pending_classes.Add(function_type_cls);
1291
1287 RegisterPrivateClass(type_ref_cls, Symbols::TypeRef(), core_lib); 1292 RegisterPrivateClass(type_ref_cls, Symbols::TypeRef(), core_lib);
1288 pending_classes.Add(type_ref_cls); 1293 pending_classes.Add(type_ref_cls);
1289 1294
1290 RegisterPrivateClass(type_parameter_cls, Symbols::TypeParameter(), core_lib); 1295 RegisterPrivateClass(type_parameter_cls, Symbols::TypeParameter(), core_lib);
1291 pending_classes.Add(type_parameter_cls); 1296 pending_classes.Add(type_parameter_cls);
1292 1297
1293 RegisterPrivateClass(bounded_type_cls, Symbols::BoundedType(), core_lib); 1298 RegisterPrivateClass(bounded_type_cls, Symbols::BoundedType(), core_lib);
1294 pending_classes.Add(bounded_type_cls); 1299 pending_classes.Add(bounded_type_cls);
1295 1300
1296 RegisterPrivateClass(mixin_app_type_cls, Symbols::MixinAppType(), core_lib); 1301 RegisterPrivateClass(mixin_app_type_cls, Symbols::MixinAppType(), core_lib);
(...skipping 17 matching lines...) Expand all
1314 cls = Class::New<Bigint>(); 1319 cls = Class::New<Bigint>();
1315 object_store->set_bigint_class(cls); 1320 object_store->set_bigint_class(cls);
1316 RegisterPrivateClass(cls, Symbols::_Bigint(), core_lib); 1321 RegisterPrivateClass(cls, Symbols::_Bigint(), core_lib);
1317 pending_classes.Add(cls); 1322 pending_classes.Add(cls);
1318 1323
1319 cls = Class::New<Double>(); 1324 cls = Class::New<Double>();
1320 object_store->set_double_class(cls); 1325 object_store->set_double_class(cls);
1321 RegisterPrivateClass(cls, Symbols::_Double(), core_lib); 1326 RegisterPrivateClass(cls, Symbols::_Double(), core_lib);
1322 pending_classes.Add(cls); 1327 pending_classes.Add(cls);
1323 1328
1324 // Abstract super class for all signature classes. 1329 // Class that represents the Dart class _Closure and C++ class Closure.
1325 cls = Class::New<Instance>(kIllegalCid); 1330 cls = Class::New<Closure>();
1326 cls.set_num_type_arguments(0); 1331 cls.set_type_arguments_field_offset(Closure::type_arguments_offset());
1332 cls.set_num_type_arguments(0); // Although a closure has type_arguments_.
1327 cls.set_num_own_type_arguments(0); 1333 cls.set_num_own_type_arguments(0);
1328 cls.set_is_prefinalized(); 1334 RegisterPrivateClass(cls, Symbols::_Closure(), core_lib);
1329 RegisterPrivateClass(cls, Symbols::FunctionImpl(), core_lib);
1330 pending_classes.Add(cls); 1335 pending_classes.Add(cls);
1331 type = Type::NewNonParameterizedType(cls); 1336 object_store->set_closure_class(cls);
1332 object_store->set_function_impl_type(type);
1333 1337
1334 cls = Class::New<WeakProperty>(); 1338 cls = Class::New<WeakProperty>();
1335 object_store->set_weak_property_class(cls); 1339 object_store->set_weak_property_class(cls);
1336 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib); 1340 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib);
1337 1341
1338 // Pre-register the mirrors library so we can place the vm class 1342 // Pre-register the mirrors library so we can place the vm class
1339 // MirrorReference there rather than the core library. 1343 // MirrorReference there rather than the core library.
1340 lib = Library::LookupLibrary(Symbols::DartMirrors()); 1344 lib = Library::LookupLibrary(Symbols::DartMirrors());
1341 if (lib.IsNull()) { 1345 if (lib.IsNull()) {
1342 lib = Library::NewLibraryHelper(Symbols::DartMirrors(), true); 1346 lib = Library::NewLibraryHelper(Symbols::DartMirrors(), true);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 // This is done to allow bootstrapping of reading classes from the snapshot. 1603 // This is done to allow bootstrapping of reading classes from the snapshot.
1600 // Some classes are not stored in the object store. Yet we still need to 1604 // Some classes are not stored in the object store. Yet we still need to
1601 // create their Class object so that they get put into the class_table 1605 // create their Class object so that they get put into the class_table
1602 // (as a side effect of Class::New()). 1606 // (as a side effect of Class::New()).
1603 1607
1604 cls = Class::New<Instance>(kInstanceCid); 1608 cls = Class::New<Instance>(kInstanceCid);
1605 object_store->set_object_class(cls); 1609 object_store->set_object_class(cls);
1606 1610
1607 cls = Class::New<LibraryPrefix>(); 1611 cls = Class::New<LibraryPrefix>();
1608 cls = Class::New<Type>(); 1612 cls = Class::New<Type>();
1613 cls = Class::New<FunctionType>();
1609 cls = Class::New<TypeRef>(); 1614 cls = Class::New<TypeRef>();
1610 cls = Class::New<TypeParameter>(); 1615 cls = Class::New<TypeParameter>();
1611 cls = Class::New<BoundedType>(); 1616 cls = Class::New<BoundedType>();
1612 cls = Class::New<MixinAppType>(); 1617 cls = Class::New<MixinAppType>();
1613 1618
1614 cls = Class::New<Array>(); 1619 cls = Class::New<Array>();
1615 object_store->set_array_class(cls); 1620 object_store->set_array_class(cls);
1616 1621
1617 cls = Class::New<Array>(kImmutableArrayCid); 1622 cls = Class::New<Array>(kImmutableArrayCid);
1618 object_store->set_immutable_array_class(cls); 1623 object_store->set_immutable_array_class(cls);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 1658
1654 cls = Class::New<Smi>(); 1659 cls = Class::New<Smi>();
1655 object_store->set_smi_class(cls); 1660 object_store->set_smi_class(cls);
1656 1661
1657 cls = Class::New<Mint>(); 1662 cls = Class::New<Mint>();
1658 object_store->set_mint_class(cls); 1663 object_store->set_mint_class(cls);
1659 1664
1660 cls = Class::New<Double>(); 1665 cls = Class::New<Double>();
1661 object_store->set_double_class(cls); 1666 object_store->set_double_class(cls);
1662 1667
1668 cls = Class::New<Closure>();
1669 object_store->set_closure_class(cls);
1670
1663 cls = Class::New<Bigint>(); 1671 cls = Class::New<Bigint>();
1664 object_store->set_bigint_class(cls); 1672 object_store->set_bigint_class(cls);
1665 1673
1666 cls = Class::NewStringClass(kOneByteStringCid); 1674 cls = Class::NewStringClass(kOneByteStringCid);
1667 object_store->set_one_byte_string_class(cls); 1675 object_store->set_one_byte_string_class(cls);
1668 1676
1669 cls = Class::NewStringClass(kTwoByteStringCid); 1677 cls = Class::NewStringClass(kTwoByteStringCid);
1670 object_store->set_two_byte_string_class(cls); 1678 object_store->set_two_byte_string_class(cls);
1671 1679
1672 cls = Class::NewStringClass(kExternalOneByteStringCid); 1680 cls = Class::NewStringClass(kExternalOneByteStringCid);
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 return raw_ptr()->user_name_; 1954 return raw_ptr()->user_name_;
1947 } 1955 }
1948 1956
1949 1957
1950 bool Class::IsInFullSnapshot() const { 1958 bool Class::IsInFullSnapshot() const {
1951 NoSafepointScope no_safepoint; 1959 NoSafepointScope no_safepoint;
1952 return raw_ptr()->library_->ptr()->is_in_fullsnapshot_; 1960 return raw_ptr()->library_->ptr()->is_in_fullsnapshot_;
1953 } 1961 }
1954 1962
1955 1963
1956 RawType* Class::SignatureType() const {
1957 ASSERT(IsSignatureClass());
1958 Zone* zone = Thread::Current()->zone();
1959 const Function& function = Function::Handle(zone, signature_function());
1960 ASSERT(!function.IsNull());
1961 if (function.signature_class() != raw()) {
1962 // This class is a function type alias. Return the canonical signature type.
1963 const Class& canonical_signature_class =
1964 Class::Handle(zone, function.signature_class());
1965 return canonical_signature_class.SignatureType();
1966 }
1967 const Type& signature_type = Type::Handle(zone, CanonicalType());
1968 if (!signature_type.IsNull()) {
1969 return signature_type.raw();
1970 }
1971 // A signature class extends class Instance and is parameterized in the same
1972 // way as the owner class of its non-static signature function.
1973 // It is not type parameterized if its signature function is static.
1974 // See Class::NewSignatureClass() for the setup of its type parameters.
1975 // During type finalization, the type arguments of the super class of the
1976 // owner class of its signature function will be prepended to the type
1977 // argument vector. Therefore, we only need to set the type arguments
1978 // matching the type parameters here.
1979 const TypeArguments& signature_type_arguments =
1980 TypeArguments::Handle(zone, type_parameters());
1981 // Return the still unfinalized signature type.
1982 return Type::New(*this, signature_type_arguments, token_pos());
1983 }
1984
1985
1986 RawAbstractType* Class::RareType() const { 1964 RawAbstractType* Class::RareType() const {
1987 const Type& type = Type::Handle(Type::New( 1965 const Type& type = Type::Handle(Type::New(
1988 *this, 1966 *this,
1989 Object::null_type_arguments(), 1967 Object::null_type_arguments(),
1990 Token::kNoSourcePos)); 1968 Token::kNoSourcePos));
1991 return ClassFinalizer::FinalizeType(*this, 1969 return ClassFinalizer::FinalizeType(*this,
1992 type, 1970 type,
1993 ClassFinalizer::kCanonicalize); 1971 ClassFinalizer::kCanonicalize);
1994 } 1972 }
1995 1973
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
2451 // resolved, which is checked by the type_class() call on the super type. 2429 // resolved, which is checked by the type_class() call on the super type.
2452 // Note that calling type_class() on a MixinAppType fails. 2430 // Note that calling type_class() on a MixinAppType fails.
2453 Thread* thread = Thread::Current(); 2431 Thread* thread = Thread::Current();
2454 Zone* zone = thread->zone(); 2432 Zone* zone = thread->zone();
2455 Isolate* isolate = thread->isolate(); 2433 Isolate* isolate = thread->isolate();
2456 Class& cls = Class::Handle(zone); 2434 Class& cls = Class::Handle(zone);
2457 AbstractType& sup_type = AbstractType::Handle(zone); 2435 AbstractType& sup_type = AbstractType::Handle(zone);
2458 cls = raw(); 2436 cls = raw();
2459 intptr_t num_type_args = 0; 2437 intptr_t num_type_args = 0;
2460 do { 2438 do {
2461 if (cls.IsSignatureClass()) {
2462 Function& signature_fun = Function::Handle(zone);
2463 signature_fun ^= cls.signature_function();
2464 if (!signature_fun.is_static() &&
2465 !signature_fun.HasInstantiatedSignature()) {
2466 cls = signature_fun.Owner();
2467 }
2468 }
2469 // Calling NumOwnTypeArguments() on a mixin application class will setup the 2439 // Calling NumOwnTypeArguments() on a mixin application class will setup the
2470 // type parameters if not already done. 2440 // type parameters if not already done.
2471 num_type_args += cls.NumOwnTypeArguments(); 2441 num_type_args += cls.NumOwnTypeArguments();
2472 // Super type of Object class is null. 2442 // Super type of Object class is null.
2473 if ((cls.super_type() == AbstractType::null()) || 2443 if ((cls.super_type() == AbstractType::null()) ||
2474 (cls.super_type() == isolate->object_store()->object_type())) { 2444 (cls.super_type() == isolate->object_store()->object_type())) {
2475 break; 2445 break;
2476 } 2446 }
2477 sup_type = cls.super_type(); 2447 sup_type = cls.super_type();
2478 ClassFinalizer::ResolveTypeClass(cls, sup_type); 2448 // A BoundedType, TypeRef, or FunctionType can appear as type argument of
2449 // sup_type, but not as sup_type itself.
2450 ASSERT(sup_type.IsType());
2451 sup_type = ClassFinalizer::ResolveTypeClass(cls, Type::Cast(sup_type));
2479 cls = sup_type.type_class(); 2452 cls = sup_type.type_class();
2453 ASSERT(!cls.IsTypedefClass());
2480 } while (true); 2454 } while (true);
2481 set_num_type_arguments(num_type_args); 2455 set_num_type_arguments(num_type_args);
2482 return num_type_args; 2456 return num_type_args;
2483 } 2457 }
2484 2458
2485 2459
2486 RawClass* Class::SuperClass() const { 2460 RawClass* Class::SuperClass() const {
2487 if (super_type() == AbstractType::null()) { 2461 if (super_type() == AbstractType::null()) {
2488 return Class::null(); 2462 return Class::null();
2489 } 2463 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2521 if (type_param_name.Equals(type_name)) { 2495 if (type_param_name.Equals(type_name)) {
2522 return type_param.raw(); 2496 return type_param.raw();
2523 } 2497 }
2524 } 2498 }
2525 } 2499 }
2526 return TypeParameter::null(); 2500 return TypeParameter::null();
2527 } 2501 }
2528 2502
2529 2503
2530 void Class::CalculateFieldOffsets() const { 2504 void Class::CalculateFieldOffsets() const {
2505 ASSERT(id() != kClosureCid); // Class _Closure is prefinalized.
2531 Array& flds = Array::Handle(fields()); 2506 Array& flds = Array::Handle(fields());
2532 const Class& super = Class::Handle(SuperClass()); 2507 const Class& super = Class::Handle(SuperClass());
2533 intptr_t offset = 0; 2508 intptr_t offset = 0;
2534 intptr_t type_args_field_offset = kNoTypeArguments; 2509 intptr_t type_args_field_offset = kNoTypeArguments;
2535 if (super.IsNull()) { 2510 if (super.IsNull()) {
2536 offset = Instance::NextFieldOffset(); 2511 offset = Instance::NextFieldOffset();
2537 ASSERT(offset > 0); 2512 ASSERT(offset > 0);
2538 } else { 2513 } else {
2539 ASSERT(super.is_finalized() || super.is_prefinalized()); 2514 ASSERT(super.is_finalized() || super.is_prefinalized());
2540 type_args_field_offset = super.type_arguments_field_offset(); 2515 type_args_field_offset = super.type_arguments_field_offset();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2734 } 2709 }
2735 2710
2736 2711
2737 void Class::set_invocation_dispatcher_cache(const Array& cache) const { 2712 void Class::set_invocation_dispatcher_cache(const Array& cache) const {
2738 StorePointer(&raw_ptr()->invocation_dispatcher_cache_, cache.raw()); 2713 StorePointer(&raw_ptr()->invocation_dispatcher_cache_, cache.raw());
2739 } 2714 }
2740 2715
2741 2716
2742 void Class::Finalize() const { 2717 void Class::Finalize() const {
2743 ASSERT(Thread::Current()->IsMutatorThread()); 2718 ASSERT(Thread::Current()->IsMutatorThread());
2744 // Even if all regular classes are prefinalized (precompilation), signature 2719 ASSERT(!Isolate::Current()->all_classes_finalized());
2745 // classes may be added later when we encounter local functions.
2746 ASSERT(IsSignatureClass() || !Isolate::Current()->all_classes_finalized());
2747 ASSERT(!is_finalized()); 2720 ASSERT(!is_finalized());
2748 // Prefinalized classes have a VM internal representation and no Dart fields. 2721 // Prefinalized classes have a VM internal representation and no Dart fields.
2749 // Their instance size is precomputed and field offsets are known. 2722 // Their instance size is precomputed and field offsets are known.
2750 if (!is_prefinalized()) { 2723 if (!is_prefinalized()) {
2751 // Compute offsets of instance fields and instance size. 2724 // Compute offsets of instance fields and instance size.
2752 CalculateFieldOffsets(); 2725 CalculateFieldOffsets();
2753 } 2726 }
2754 set_is_finalized(); 2727 set_is_finalized();
2755 } 2728 }
2756 2729
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
3121 const Script& script, 3094 const Script& script,
3122 intptr_t token_pos) { 3095 intptr_t token_pos) {
3123 Class& result = Class::Handle(New<Instance>(kIllegalCid)); 3096 Class& result = Class::Handle(New<Instance>(kIllegalCid));
3124 result.set_name(name); 3097 result.set_name(name);
3125 result.set_script(script); 3098 result.set_script(script);
3126 result.set_token_pos(token_pos); 3099 result.set_token_pos(token_pos);
3127 return result.raw(); 3100 return result.raw();
3128 } 3101 }
3129 3102
3130 3103
3131 RawClass* Class::NewSignatureClass(const String& name,
3132 const Function& signature_function,
3133 const Script& script,
3134 intptr_t token_pos) {
3135 const Class& result = Class::Handle(New(name, script, token_pos));
3136 // Instances of a signature class can only be closures.
3137 result.set_instance_size(Closure::InstanceSize());
3138 result.set_next_field_offset(Closure::NextFieldOffset());
3139 // Signature classes extend the _FunctionImpl class.
3140 result.set_super_type(Type::Handle(
3141 Isolate::Current()->object_store()->function_impl_type()));
3142 result.set_is_synthesized_class();
3143 result.set_type_arguments_field_offset(Closure::type_arguments_offset());
3144 if (!signature_function.IsNull()) {
3145 result.PatchSignatureFunction(signature_function);
3146 }
3147 return result.raw();
3148 }
3149
3150
3151 void Class::PatchSignatureFunction(const Function& signature_function) const {
3152 ASSERT(!signature_function.IsNull());
3153 set_signature_function(signature_function);
3154 const Class& owner_class = Class::Handle(signature_function.Owner());
3155 ASSERT(!owner_class.IsNull());
3156 // A signature class extends class Instance and is either not parameterized or
3157 // parameterized with exactly the same list of type parameters as the owner
3158 // class of its function.
3159 // In case of a function type alias, the function owner is the alias class,
3160 // which is also the signature class. The signature class is therefore
3161 // parameterized according to the alias class declaration, even if the
3162 // function type is not generic.
3163 // Otherwise, if the function is static or if its signature type is
3164 // non-generic, i.e. it does not depend on any type parameter of the owner
3165 // class, then the signature class is not parameterized, although the owner
3166 // class may be.
3167 if (owner_class.raw() == raw()) {
3168 // This signature class is an alias, which cannot be the canonical
3169 // signature class for this signature function.
3170 ASSERT(!IsCanonicalSignatureClass());
3171 // Do not modify the declared type parameters of the alias, even if unused.
3172 } else {
3173 // Copy the type parameters only for an instance function type that is not
3174 // instantiated, i.e. that depends on the type parameters of the owner
3175 // class.
3176 // TODO(regis): Verify that it is not a problem for the copied type
3177 // parameters to refer to the owner class rather than to the signature
3178 // class. In other words, uninstantiated function types should only get
3179 // instantiated by the owner class as instantiator and never by the
3180 // signature class itself.
3181 TypeArguments& type_parameters = TypeArguments::Handle();
3182 if (!signature_function.is_static() &&
3183 (owner_class.NumTypeParameters() > 0) &&
3184 !signature_function.HasInstantiatedSignature()) {
3185 type_parameters = owner_class.type_parameters();
3186 }
3187 set_type_parameters(type_parameters);
3188 if (signature_function.signature_class() == Object::null()) {
3189 // Make this signature class the canonical signature class.
3190 signature_function.set_signature_class(*this);
3191 ASSERT(IsCanonicalSignatureClass());
3192 }
3193 }
3194 set_is_prefinalized();
3195 }
3196
3197
3198 RawClass* Class::NewNativeWrapper(const Library& library, 3104 RawClass* Class::NewNativeWrapper(const Library& library,
3199 const String& name, 3105 const String& name,
3200 int field_count) { 3106 int field_count) {
3201 Class& cls = Class::Handle(library.LookupClass(name)); 3107 Class& cls = Class::Handle(library.LookupClass(name));
3202 if (cls.IsNull()) { 3108 if (cls.IsNull()) {
3203 cls = New(name, Script::Handle(), Token::kNoSourcePos); 3109 cls = New(name, Script::Handle(), Token::kNoSourcePos);
3204 cls.SetFields(Object::empty_array()); 3110 cls.SetFields(Object::empty_array());
3205 cls.SetFunctions(Object::empty_array()); 3111 cls.SetFunctions(Object::empty_array());
3206 // Set super class to Object. 3112 // Set super class to Object.
3207 cls.set_super_type(Type::Handle(Type::ObjectType())); 3113 cls.set_super_type(Type::Handle(Type::ObjectType()));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3285 } 3191 }
3286 } 3192 }
3287 3193
3288 3194
3289 void Class::set_user_name(const String& value) const { 3195 void Class::set_user_name(const String& value) const {
3290 StorePointer(&raw_ptr()->user_name_, value.raw()); 3196 StorePointer(&raw_ptr()->user_name_, value.raw());
3291 } 3197 }
3292 3198
3293 3199
3294 RawString* Class::GeneratePrettyName() const { 3200 RawString* Class::GeneratePrettyName() const {
3295 if (!IsCanonicalSignatureClass()) { 3201 const String& name = String::Handle(Name());
3296 const String& name = String::Handle(Name()); 3202 return String::IdentifierPrettyName(name);
3297 return String::IdentifierPrettyName(name);
3298 } else {
3299 return Name();
3300 }
3301 } 3203 }
3302 3204
3303 3205
3304 RawString* Class::GenerateUserVisibleName() const { 3206 RawString* Class::GenerateUserVisibleName() const {
3305 if (FLAG_show_internal_names) { 3207 if (FLAG_show_internal_names) {
3306 return Name(); 3208 return Name();
3307 } 3209 }
3308 switch (id()) { 3210 switch (id()) {
3309 case kNullCid: 3211 case kNullCid:
3310 return Symbols::Null().raw(); 3212 return Symbols::Null().raw();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
3428 case kTypedDataFloat64x2ArrayCid: 3330 case kTypedDataFloat64x2ArrayCid:
3429 case kExternalTypedDataFloat64x2ArrayCid: 3331 case kExternalTypedDataFloat64x2ArrayCid:
3430 return Symbols::Float64x2List().raw(); 3332 return Symbols::Float64x2List().raw();
3431 case kTypedDataFloat32ArrayCid: 3333 case kTypedDataFloat32ArrayCid:
3432 case kExternalTypedDataFloat32ArrayCid: 3334 case kExternalTypedDataFloat32ArrayCid:
3433 return Symbols::Float32List().raw(); 3335 return Symbols::Float32List().raw();
3434 case kTypedDataFloat64ArrayCid: 3336 case kTypedDataFloat64ArrayCid:
3435 case kExternalTypedDataFloat64ArrayCid: 3337 case kExternalTypedDataFloat64ArrayCid:
3436 return Symbols::Float64List().raw(); 3338 return Symbols::Float64List().raw();
3437 default: 3339 default:
3438 if (!IsCanonicalSignatureClass()) { 3340 const String& name = String::Handle(Name());
3439 const String& name = String::Handle(Name()); 3341 return String::IdentifierPrettyName(name);
3440 return String::IdentifierPrettyName(name);
3441 } else {
3442 return Name();
3443 }
3444 } 3342 }
3445 UNREACHABLE(); 3343 UNREACHABLE();
3446 } 3344 }
3447 3345
3448 3346
3449 void Class::set_script(const Script& value) const { 3347 void Class::set_script(const Script& value) const {
3450 StorePointer(&raw_ptr()->script_, value.raw()); 3348 StorePointer(&raw_ptr()->script_, value.raw());
3451 } 3349 }
3452 3350
3453 3351
3454 void Class::set_token_pos(intptr_t token_pos) const { 3352 void Class::set_token_pos(intptr_t token_pos) const {
3455 ASSERT(!Token::IsClassifying(token_pos)); 3353 ASSERT(!Token::IsClassifying(token_pos));
3456 StoreNonPointer(&raw_ptr()->token_pos_, token_pos); 3354 StoreNonPointer(&raw_ptr()->token_pos_, token_pos);
3457 } 3355 }
3458 3356
3459 3357
3460 intptr_t Class::ComputeEndTokenPos() const { 3358 intptr_t Class::ComputeEndTokenPos() const {
3461 // Return the begin token for synthetic classes. 3359 // Return the begin token for synthetic classes.
3462 if (IsSignatureClass() || IsMixinApplication() || IsTopLevel()) { 3360 if (IsMixinApplication() || IsTopLevel()) {
3463 return token_pos(); 3361 return token_pos();
3464 } 3362 }
3465 const Script& scr = Script::Handle(script()); 3363 const Script& scr = Script::Handle(script());
3466 ASSERT(!scr.IsNull()); 3364 ASSERT(!scr.IsNull());
3467 const TokenStream& tkns = TokenStream::Handle(scr.tokens()); 3365 const TokenStream& tkns = TokenStream::Handle(scr.tokens());
3468 TokenStream::Iterator tkit( 3366 TokenStream::Iterator tkit(
3469 tkns, token_pos(), TokenStream::Iterator::kNoNewlines); 3367 tkns, token_pos(), TokenStream::Iterator::kNoNewlines);
3470 intptr_t level = 0; 3368 intptr_t level = 0;
3471 while (tkit.CurrentTokenKind() != Token::kEOS) { 3369 while (tkit.CurrentTokenKind() != Token::kEOS) {
3472 if (tkit.CurrentTokenKind() == Token::kLBRACE) { 3370 if (tkit.CurrentTokenKind() == Token::kLBRACE) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
3635 } 3533 }
3636 3534
3637 3535
3638 void Class::set_canonical_types(const Object& value) const { 3536 void Class::set_canonical_types(const Object& value) const {
3639 ASSERT(!value.IsNull()); 3537 ASSERT(!value.IsNull());
3640 StorePointer(&raw_ptr()->canonical_types_, value.raw()); 3538 StorePointer(&raw_ptr()->canonical_types_, value.raw());
3641 } 3539 }
3642 3540
3643 3541
3644 RawType* Class::CanonicalType() const { 3542 RawType* Class::CanonicalType() const {
3645 if (!IsGeneric()) { 3543 if (!IsGeneric() && !IsClosureClass()) {
3646 return reinterpret_cast<RawType*>(raw_ptr()->canonical_types_); 3544 return reinterpret_cast<RawType*>(raw_ptr()->canonical_types_);
3647 } 3545 }
3648 Array& types = Array::Handle(); 3546 Array& types = Array::Handle();
3649 types ^= canonical_types(); 3547 types ^= canonical_types();
3650 if (!types.IsNull() && (types.Length() > 0)) { 3548 if (!types.IsNull() && (types.Length() > 0)) {
3651 return reinterpret_cast<RawType*>(types.At(0)); 3549 return reinterpret_cast<RawType*>(types.At(0));
3652 } 3550 }
3653 return reinterpret_cast<RawType*>(Object::null()); 3551 return reinterpret_cast<RawType*>(Object::null());
3654 } 3552 }
3655 3553
3656 3554
3657 void Class::SetCanonicalType(const Type& type) const { 3555 void Class::SetCanonicalType(const Type& type) const {
3658 ASSERT(type.IsCanonical()); 3556 ASSERT(type.IsCanonical());
3659 if (!IsGeneric()) { 3557 if (!IsGeneric() && !IsClosureClass()) {
3660 ASSERT((canonical_types() == Object::null()) || 3558 ASSERT((canonical_types() == Object::null()) ||
3661 (canonical_types() == type.raw())); // Set during own finalization. 3559 (canonical_types() == type.raw())); // Set during own finalization.
3662 set_canonical_types(type); 3560 set_canonical_types(type);
3663 } else { 3561 } else {
3664 Array& types = Array::Handle(); 3562 Array& types = Array::Handle();
3665 types ^= canonical_types(); 3563 types ^= canonical_types();
3666 ASSERT(!types.IsNull() && (types.Length() > 1)); 3564 ASSERT(!types.IsNull() && (types.Length() > 1));
3667 ASSERT((types.At(0) == Object::null()) || (types.At(0) == type.raw())); 3565 ASSERT((types.At(0) == Object::null()) || (types.At(0) == type.raw()));
3668 types.SetAt(0, type); 3566 types.SetAt(0, type);
3669 } 3567 }
3670 } 3568 }
3671 3569
3672 3570
3673 intptr_t Class::FindCanonicalTypeIndex(const Type& needle) const { 3571 intptr_t Class::FindCanonicalTypeIndex(const AbstractType& needle) const {
3674 Thread* thread = Thread::Current(); 3572 Thread* thread = Thread::Current();
3675 if (EnsureIsFinalized(thread) != Error::null()) { 3573 if (EnsureIsFinalized(thread) != Error::null()) {
3676 return -1; 3574 return -1;
3677 } 3575 }
3678 if (needle.raw() == CanonicalType()) { 3576 if (needle.raw() == CanonicalType()) {
3679 // For a generic type or signature type, there exists another index with the 3577 // For a generic type or signature type, there exists another index with the
3680 // same type. It will never be returned by this function. 3578 // same type. It will never be returned by this function.
3681 return 0; 3579 return 0;
3682 } 3580 }
3683 REUSABLE_OBJECT_HANDLESCOPE(thread); 3581 REUSABLE_OBJECT_HANDLESCOPE(thread);
3684 Object& types = thread->ObjectHandle(); 3582 Object& types = thread->ObjectHandle();
3685 types = canonical_types(); 3583 types = canonical_types();
3686 if (types.IsNull()) { 3584 if (types.IsNull()) {
3687 return -1; 3585 return -1;
3688 } 3586 }
3689 const intptr_t len = Array::Cast(types).Length(); 3587 const intptr_t len = Array::Cast(types).Length();
3690 REUSABLE_ABSTRACT_TYPE_HANDLESCOPE(thread); 3588 REUSABLE_ABSTRACT_TYPE_HANDLESCOPE(thread);
3691 AbstractType& type = thread->AbstractTypeHandle(); 3589 AbstractType& type = thread->AbstractTypeHandle();
3692 for (intptr_t i = 0; i < len; i++) { 3590 for (intptr_t i = 0; i < len; i++) {
3693 type ^= Array::Cast(types).At(i); 3591 type ^= Array::Cast(types).At(i);
3694 if (needle.raw() == type.raw()) { 3592 if (needle.raw() == type.raw()) {
3695 return i; 3593 return i;
3696 } 3594 }
3697 } 3595 }
3698 // No type found. 3596 // No type found.
3699 return -1; 3597 return -1;
3700 } 3598 }
3701 3599
3702 3600
3703 RawType* Class::CanonicalTypeFromIndex(intptr_t idx) const { 3601 RawAbstractType* Class::CanonicalTypeFromIndex(intptr_t idx) const {
3704 Type& type = Type::Handle(); 3602 AbstractType& type = AbstractType::Handle();
3705 if (idx == 0) { 3603 if (idx == 0) {
3706 type = CanonicalType(); 3604 type = CanonicalType();
3707 if (!type.IsNull()) { 3605 if (!type.IsNull()) {
3708 return type.raw(); 3606 return type.raw();
3709 } 3607 }
3710 } 3608 }
3711 Object& types = Object::Handle(canonical_types()); 3609 Object& types = Object::Handle(canonical_types());
3712 if (types.IsNull() || !types.IsArray()) { 3610 if (types.IsNull() || !types.IsArray()) {
3713 return Type::null(); 3611 return Type::null();
3714 } 3612 }
(...skipping 26 matching lines...) Expand all
3741 // Disassociate the existing stub from class. 3639 // Disassociate the existing stub from class.
3742 StorePointer(&raw_ptr()->allocation_stub_, Code::null()); 3640 StorePointer(&raw_ptr()->allocation_stub_, Code::null());
3743 } 3641 }
3744 3642
3745 3643
3746 bool Class::IsFunctionClass() const { 3644 bool Class::IsFunctionClass() const {
3747 return raw() == Type::Handle(Type::Function()).type_class(); 3645 return raw() == Type::Handle(Type::Function()).type_class();
3748 } 3646 }
3749 3647
3750 3648
3751 bool Class::IsCanonicalSignatureClass() const {
3752 const Function& function = Function::Handle(signature_function());
3753 return (!function.IsNull() && (function.signature_class() == raw()));
3754 }
3755
3756
3757 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T. 3649 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T.
3758 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T. 3650 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T.
3759 // Type S is specified by this class parameterized with 'type_arguments', and 3651 // Type S is specified by this class parameterized with 'type_arguments', and
3760 // type T by class 'other' parameterized with 'other_type_arguments'. 3652 // type T by class 'other' parameterized with 'other_type_arguments'.
3761 // This class and class 'other' do not need to be finalized, however, they must 3653 // This class and class 'other' do not need to be finalized, however, they must
3762 // be resolved as well as their interfaces. 3654 // be resolved as well as their interfaces.
3763 bool Class::TypeTestNonRecursive(const Class& cls, 3655 bool Class::TypeTestNonRecursive(const Class& cls,
3764 Class::TypeTestKind test_kind, 3656 Class::TypeTestKind test_kind,
3765 const TypeArguments& type_arguments, 3657 const TypeArguments& type_arguments,
3766 const Class& other, 3658 const Class& other,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3819 // above. 3711 // above.
3820 return test_kind == Class::kIsSubtypeOf; 3712 return test_kind == Class::kIsSubtypeOf;
3821 } 3713 }
3822 return type_arguments.TypeTest(test_kind, 3714 return type_arguments.TypeTest(test_kind,
3823 other_type_arguments, 3715 other_type_arguments,
3824 from_index, 3716 from_index,
3825 num_type_params, 3717 num_type_params,
3826 bound_error, 3718 bound_error,
3827 space); 3719 space);
3828 } 3720 }
3829 const bool other_is_function_class = other.IsFunctionClass(); 3721 if (other.IsFunctionClass()) {
3830 if (other.IsSignatureClass() || other_is_function_class) { 3722 // Check if type S has a call() method.
3831 const Function& other_fun = Function::Handle(zone,
3832 other.signature_function());
3833 if (thsi.IsSignatureClass()) {
3834 if (other_is_function_class) {
3835 return true;
3836 }
3837 // Check for two function types.
3838 const Function& fun =
3839 Function::Handle(zone, thsi.signature_function());
3840 return fun.TypeTest(test_kind,
3841 type_arguments,
3842 other_fun,
3843 other_type_arguments,
3844 bound_error,
3845 space);
3846 }
3847 // Check if type S has a call() method of function type T.
3848 Function& function = 3723 Function& function =
3849 Function::Handle(zone, thsi.LookupDynamicFunction(Symbols::Call())); 3724 Function::Handle(zone, thsi.LookupDynamicFunction(Symbols::Call()));
3850 if (function.IsNull()) { 3725 if (function.IsNull()) {
3851 // Walk up the super_class chain. 3726 // Walk up the super_class chain.
3852 Class& cls = Class::Handle(zone, thsi.SuperClass()); 3727 Class& cls = Class::Handle(zone, thsi.SuperClass());
3853 while (!cls.IsNull() && function.IsNull()) { 3728 while (!cls.IsNull() && function.IsNull()) {
3854 function = cls.LookupDynamicFunction(Symbols::Call()); 3729 function = cls.LookupDynamicFunction(Symbols::Call());
3855 cls = cls.SuperClass(); 3730 cls = cls.SuperClass();
3856 } 3731 }
3857 } 3732 }
3858 if (!function.IsNull()) { 3733 if (!function.IsNull()) {
3859 if (other_is_function_class || 3734 return true;
3860 function.TypeTest(test_kind,
3861 type_arguments,
3862 other_fun,
3863 other_type_arguments,
3864 bound_error,
3865 space)) {
3866 return true;
3867 }
3868 } 3735 }
3869 } 3736 }
3870 // Check for 'direct super type' specified in the implements clause 3737 // Check for 'direct super type' specified in the implements clause
3871 // and check for transitivity at the same time. 3738 // and check for transitivity at the same time.
3872 Array& interfaces = Array::Handle(zone, thsi.interfaces()); 3739 Array& interfaces = Array::Handle(zone, thsi.interfaces());
3873 AbstractType& interface = AbstractType::Handle(zone); 3740 AbstractType& interface = AbstractType::Handle(zone);
3874 Class& interface_class = Class::Handle(zone); 3741 Class& interface_class = Class::Handle(zone);
3875 TypeArguments& interface_args = TypeArguments::Handle(zone); 3742 TypeArguments& interface_args = TypeArguments::Handle(zone);
3876 Error& error = Error::Handle(zone); 3743 Error& error = Error::Handle(zone);
3877 for (intptr_t i = 0; i < interfaces.Length(); i++) { 3744 for (intptr_t i = 0; i < interfaces.Length(); i++) {
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after
4897 if (prior_instantiations.At(index) == instantiator_type_arguments.raw()) { 4764 if (prior_instantiations.At(index) == instantiator_type_arguments.raw()) {
4898 return TypeArguments::RawCast(prior_instantiations.At(index + 1)); 4765 return TypeArguments::RawCast(prior_instantiations.At(index + 1));
4899 } 4766 }
4900 if (prior_instantiations.At(index) == Smi::New(StubCode::kNoInstantiator)) { 4767 if (prior_instantiations.At(index) == Smi::New(StubCode::kNoInstantiator)) {
4901 break; 4768 break;
4902 } 4769 }
4903 index += 2; 4770 index += 2;
4904 } 4771 }
4905 // Cache lookup failed. Instantiate the type arguments. 4772 // Cache lookup failed. Instantiate the type arguments.
4906 TypeArguments& result = TypeArguments::Handle(); 4773 TypeArguments& result = TypeArguments::Handle();
4907 result = InstantiateFrom(instantiator_type_arguments, bound_error); 4774 result = InstantiateFrom(
4775 instantiator_type_arguments, bound_error, NULL, Heap::kOld);
4908 if ((bound_error != NULL) && !bound_error->IsNull()) { 4776 if ((bound_error != NULL) && !bound_error->IsNull()) {
4909 return result.raw(); 4777 return result.raw();
4910 } 4778 }
4911 // Instantiation did not result in bound error. Canonicalize type arguments. 4779 // Instantiation did not result in bound error. Canonicalize type arguments.
4912 result = result.Canonicalize(); 4780 result = result.Canonicalize();
4913 // InstantiateAndCanonicalizeFrom is not reentrant. It cannot have been called 4781 // InstantiateAndCanonicalizeFrom is not reentrant. It cannot have been called
4914 // indirectly, so the prior_instantiations array cannot have grown. 4782 // indirectly, so the prior_instantiations array cannot have grown.
4915 ASSERT(prior_instantiations.raw() == instantiations()); 4783 ASSERT(prior_instantiations.raw() == instantiations());
4916 // Add instantiator and result to instantiations array. 4784 // Add instantiator and result to instantiations array.
4917 intptr_t length = prior_instantiations.Length(); 4785 intptr_t length = prior_instantiations.Length();
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
5489 ASSERT(obj.IsArray()); 5357 ASSERT(obj.IsArray());
5490 ASSERT((Array::Cast(obj).At(1) == Object::null()) || value.IsNull()); 5358 ASSERT((Array::Cast(obj).At(1) == Object::null()) || value.IsNull());
5491 Array::Cast(obj).SetAt(1, value); 5359 Array::Cast(obj).SetAt(1, value);
5492 } else { 5360 } else {
5493 ASSERT((raw_ptr()->data_ == Object::null()) || value.IsNull()); 5361 ASSERT((raw_ptr()->data_ == Object::null()) || value.IsNull());
5494 set_data(value); 5362 set_data(value);
5495 } 5363 }
5496 } 5364 }
5497 5365
5498 5366
5499 RawClass* Function::signature_class() const { 5367 RawFunctionType* Function::SignatureType() const {
5368 FunctionType& type = FunctionType::Handle();
5369 const Object& obj = Object::Handle(raw_ptr()->data_);
5500 if (IsSignatureFunction()) { 5370 if (IsSignatureFunction()) {
5501 const Object& obj = Object::Handle(raw_ptr()->data_); 5371 ASSERT(obj.IsNull() || obj.IsFunctionType());
5502 ASSERT(obj.IsNull() || obj.IsClass()); 5372 type = obj.IsNull() ? FunctionType::null() : FunctionType::Cast(obj).raw();
5503 return (obj.IsNull()) ? Class::null() : Class::Cast(obj).raw(); 5373 } else {
5374 ASSERT(IsClosureFunction());
5375 ASSERT(!obj.IsNull());
5376 type = ClosureData::Cast(obj).signature_type();
5504 } 5377 }
5505 if (IsClosureFunction()) { 5378 if (type.IsNull()) {
5506 const Object& obj = Object::Handle(raw_ptr()->data_); 5379 // A function type is parameterized in the same way as the owner class of
5507 ASSERT(!obj.IsNull()); 5380 // its non-static signature function.
5508 return ClosureData::Cast(obj).signature_class(); 5381 // It is not type parameterized if its signature function is static.
5382 // During type finalization, the type arguments of the super class of the
5383 // owner class of its signature function will be prepended to the type
5384 // argument vector. Therefore, we only need to set the type arguments
5385 // matching the type parameters here.
5386 // In case of a function type alias, the function owner is the alias class,
5387 // i.e. the typedef. The signature type is therefore parameterized according
5388 // to the alias class declaration, even if the function type is not generic.
5389 // Otherwise, if the function is static or if its signature type is
5390 // non-generic, i.e. it does not depend on any type parameter of the owner
5391 // class, then the signature type is not parameterized, although the owner
5392 // class may be. In this case, the scope class of the function type is reset
5393 // to _Closure class as well as the owner of the signature function.
5394 Class& scope_class = Class::Handle(Owner());
5395 if (!scope_class.IsTypedefClass() &&
5396 (is_static() ||
5397 !scope_class.IsGeneric() ||
5398 HasInstantiatedSignature())) {
5399 scope_class = Isolate::Current()->object_store()->closure_class();
5400 if (IsSignatureFunction()) {
5401 set_owner(scope_class);
5402 set_token_pos(Token::kNoSourcePos);
5403 }
5404 }
5405 const TypeArguments& signature_type_arguments =
5406 TypeArguments::Handle(scope_class.type_parameters());
5407 // Return the still unfinalized signature type.
5408 type = FunctionType::New(scope_class,
5409 signature_type_arguments,
5410 *this,
5411 token_pos());
5412
5413 SetSignatureType(type);
5509 } 5414 }
5510 return Class::null(); 5415 return type.raw();
5511 } 5416 }
5512 5417
5513 5418
5514 void Function::set_signature_class(const Class& value) const { 5419 void Function::SetSignatureType(const FunctionType& value) const {
5515 if (IsSignatureFunction()) { 5420 if (IsSignatureFunction()) {
5516 set_data(value); 5421 set_data(value);
5517 return; 5422 } else {
5518 } 5423 ASSERT(IsClosureFunction());
5519 if (IsClosureFunction()) {
5520 const Object& obj = Object::Handle(raw_ptr()->data_); 5424 const Object& obj = Object::Handle(raw_ptr()->data_);
5521 ASSERT(!obj.IsNull()); 5425 ASSERT(!obj.IsNull());
5522 ClosureData::Cast(obj).set_signature_class(value); 5426 ClosureData::Cast(obj).set_signature_type(value);
5523 return;
5524 } 5427 }
5525 UNREACHABLE();
5526 } 5428 }
5527 5429
5528 5430
5529 bool Function::IsRedirectingFactory() const { 5431 bool Function::IsRedirectingFactory() const {
5530 if (!IsFactory() || !is_redirecting()) { 5432 if (!IsFactory() || !is_redirecting()) {
5531 return false; 5433 return false;
5532 } 5434 }
5533 ASSERT(!IsClosureFunction()); // A factory cannot also be a closure. 5435 ASSERT(!IsClosureFunction()); // A factory cannot also be a closure.
5534 return true; 5436 return true;
5535 } 5437 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
5636 if (obj.IsNull()) { 5538 if (obj.IsNull()) {
5637 obj = RedirectionData::New(); 5539 obj = RedirectionData::New();
5638 set_data(obj); 5540 set_data(obj);
5639 } 5541 }
5640 RedirectionData::Cast(obj).set_target(target); 5542 RedirectionData::Cast(obj).set_target(target);
5641 } 5543 }
5642 5544
5643 5545
5644 // This field is heavily overloaded: 5546 // This field is heavily overloaded:
5645 // eval function: Script expression source 5547 // eval function: Script expression source
5646 // signature function: Class signature class 5548 // signature function: Function type
5647 // method extractor: Function extracted closure function 5549 // method extractor: Function extracted closure function
5648 // noSuchMethod dispatcher: Array arguments descriptor 5550 // noSuchMethod dispatcher: Array arguments descriptor
5649 // invoke-field dispatcher: Array arguments descriptor 5551 // invoke-field dispatcher: Array arguments descriptor
5650 // redirecting constructor: RedirectionData 5552 // redirecting constructor: RedirectionData
5651 // closure function: ClosureData 5553 // closure function: ClosureData
5652 // irregexp function: Array[0] = JSRegExp 5554 // irregexp function: Array[0] = JSRegExp
5653 // Array[1] = Smi string specialization cid 5555 // Array[1] = Smi string specialization cid
5654 // native function: Array[0] = String native name 5556 // native function: Array[0] = String native name
5655 // Array[1] = Function implicit closure function 5557 // Array[1] = Function implicit closure function
5656 // regular function: Function for implicit closure function 5558 // regular function: Function for implicit closure function
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
6502 /* is_abstract = */ false, 6404 /* is_abstract = */ false,
6503 /* is_external = */ false, 6405 /* is_external = */ false,
6504 parent.is_native(), 6406 parent.is_native(),
6505 parent_owner, 6407 parent_owner,
6506 token_pos)); 6408 token_pos));
6507 result.set_parent_function(parent); 6409 result.set_parent_function(parent);
6508 return result.raw(); 6410 return result.raw();
6509 } 6411 }
6510 6412
6511 6413
6414 RawFunction* Function::NewSignatureFunction(const Class& owner,
6415 intptr_t token_pos) {
6416 const Function& result = Function::Handle(Function::New(
6417 Symbols::AnonymousSignature(),
6418 RawFunction::kSignatureFunction,
6419 /* is_static = */ false,
6420 /* is_const = */ false,
6421 /* is_abstract = */ false,
6422 /* is_external = */ false,
6423 /* is_native = */ false,
6424 owner, // Same as function type scope class.
6425 token_pos));
6426 result.set_is_reflectable(false);
6427 result.set_is_visible(false);
6428 result.set_is_debuggable(false);
6429 return result.raw();
6430 }
6431
6432
6512 RawFunction* Function::NewEvalFunction(const Class& owner, 6433 RawFunction* Function::NewEvalFunction(const Class& owner,
6513 const Script& script, 6434 const Script& script,
6514 bool is_static) { 6435 bool is_static) {
6515 const Function& result = Function::Handle( 6436 const Function& result = Function::Handle(
6516 Function::New(String::Handle(Symbols::New(":Eval")), 6437 Function::New(String::Handle(Symbols::New(":Eval")),
6517 RawFunction::kRegularFunction, 6438 RawFunction::kRegularFunction,
6518 is_static, 6439 is_static,
6519 /* is_const = */ false, 6440 /* is_const = */ false,
6520 /* is_abstract = */ false, 6441 /* is_abstract = */ false,
6521 /* is_external = */ false, 6442 /* is_external = */ false,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
6580 // Add implicit closure object parameter. 6501 // Add implicit closure object parameter.
6581 param_type = Type::DynamicType(); 6502 param_type = Type::DynamicType();
6582 closure_function.SetParameterTypeAt(0, param_type); 6503 closure_function.SetParameterTypeAt(0, param_type);
6583 closure_function.SetParameterNameAt(0, Symbols::ClosureParameter()); 6504 closure_function.SetParameterNameAt(0, Symbols::ClosureParameter());
6584 for (int i = kClosure; i < num_params; i++) { 6505 for (int i = kClosure; i < num_params; i++) {
6585 param_type = ParameterTypeAt(has_receiver - kClosure + i); 6506 param_type = ParameterTypeAt(has_receiver - kClosure + i);
6586 closure_function.SetParameterTypeAt(i, param_type); 6507 closure_function.SetParameterTypeAt(i, param_type);
6587 param_name = ParameterNameAt(has_receiver - kClosure + i); 6508 param_name = ParameterNameAt(has_receiver - kClosure + i);
6588 closure_function.SetParameterNameAt(i, param_name); 6509 closure_function.SetParameterNameAt(i, param_name);
6589 } 6510 }
6590 6511 const FunctionType& signature_type =
6591 // Lookup or create a new signature class for the closure function in the 6512 FunctionType::Handle(closure_function.SignatureType());
6592 // library of the owner class.
6593 const Class& owner_class = Class::Handle(Owner());
6594 ASSERT(!owner_class.IsNull() && (Owner() == closure_function.Owner()));
6595 const Library& library = Library::Handle(owner_class.library());
6596 ASSERT(!library.IsNull());
6597 const String& signature = String::Handle(closure_function.Signature());
6598 Class& signature_class = Class::ZoneHandle(
6599 library.LookupLocalClass(signature));
6600 if (signature_class.IsNull()) {
6601 const Script& script = Script::Handle(this->script());
6602 signature_class = Class::NewSignatureClass(signature,
6603 closure_function,
6604 script,
6605 closure_function.token_pos());
6606 library.AddClass(signature_class);
6607 } else {
6608 closure_function.set_signature_class(signature_class);
6609 }
6610 // Finalize types in signature class here, so that the
6611 // signature type is not computed twice.
6612 ClassFinalizer::FinalizeTypesInClass(signature_class);
6613 const Type& signature_type = Type::Handle(signature_class.SignatureType());
6614 if (!signature_type.IsFinalized()) { 6513 if (!signature_type.IsFinalized()) {
6615 ClassFinalizer::FinalizeType( 6514 ClassFinalizer::FinalizeType(
6616 signature_class, signature_type, ClassFinalizer::kCanonicalize); 6515 Class::Handle(Owner()), signature_type, ClassFinalizer::kCanonicalize);
6617 } 6516 }
6618 ASSERT(closure_function.signature_class() == signature_class.raw());
6619 set_implicit_closure_function(closure_function); 6517 set_implicit_closure_function(closure_function);
6620 ASSERT(closure_function.IsImplicitClosureFunction()); 6518 ASSERT(closure_function.IsImplicitClosureFunction());
6621 return closure_function.raw(); 6519 return closure_function.raw();
6622 } 6520 }
6623 6521
6624 6522
6625 void Function::DropUncompiledImplicitClosureFunction() const { 6523 void Function::DropUncompiledImplicitClosureFunction() const {
6626 if (implicit_closure_function() != Function::null()) { 6524 if (implicit_closure_function() != Function::null()) {
6627 const Function& func = Function::Handle(implicit_closure_function()); 6525 const Function& func = Function::Handle(implicit_closure_function());
6628 if (!func.HasCode()) { 6526 if (!func.HasCode()) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
6713 RawInstance* Function::ImplicitStaticClosure() const { 6611 RawInstance* Function::ImplicitStaticClosure() const {
6714 if (implicit_static_closure() == Instance::null()) { 6612 if (implicit_static_closure() == Instance::null()) {
6715 Thread* thread = Thread::Current(); 6613 Thread* thread = Thread::Current();
6716 Isolate* isolate = thread->isolate(); 6614 Isolate* isolate = thread->isolate();
6717 Zone* zone = thread->zone(); 6615 Zone* zone = thread->zone();
6718 ObjectStore* object_store = isolate->object_store(); 6616 ObjectStore* object_store = isolate->object_store();
6719 const Context& context = 6617 const Context& context =
6720 Context::Handle(zone, object_store->empty_context()); 6618 Context::Handle(zone, object_store->empty_context());
6721 Instance& closure = 6619 Instance& closure =
6722 Instance::Handle(zone, Closure::New(*this, context, Heap::kOld)); 6620 Instance::Handle(zone, Closure::New(*this, context, Heap::kOld));
6723 const char* error_str = NULL;
6724 closure ^= closure.CheckAndCanonicalize(&error_str);
6725 ASSERT(!closure.IsNull());
6726 set_implicit_static_closure(closure); 6621 set_implicit_static_closure(closure);
6727 } 6622 }
6728 return implicit_static_closure(); 6623 return implicit_static_closure();
6729 } 6624 }
6730 6625
6731 6626
6732 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const { 6627 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const {
6733 ASSERT(IsImplicitClosureFunction()); 6628 ASSERT(IsImplicitClosureFunction());
6734 const Class& cls = Class::Handle(signature_class()); 6629 const FunctionType& signature_type = FunctionType::Handle(SignatureType());
6630 const Class& cls = Class::Handle(signature_type.type_class());
6735 const Context& context = Context::Handle(Context::New(1)); 6631 const Context& context = Context::Handle(Context::New(1));
6736 context.SetAt(0, receiver); 6632 context.SetAt(0, receiver);
6737 const Instance& result = Instance::Handle(Closure::New(*this, context)); 6633 const Instance& result = Instance::Handle(Closure::New(*this, context));
6738 if (cls.NumTypeArguments() > 0) { 6634 if (cls.IsGeneric()) {
6739 const TypeArguments& type_arguments = 6635 const TypeArguments& type_arguments =
6740 TypeArguments::Handle(receiver.GetTypeArguments()); 6636 TypeArguments::Handle(receiver.GetTypeArguments());
6741 result.SetTypeArguments(type_arguments); 6637 result.SetTypeArguments(type_arguments);
6742 } 6638 }
6743 return result.raw(); 6639 return result.raw();
6744 } 6640 }
6745 6641
6746 6642
6747 RawString* Function::BuildSignature(bool instantiate, 6643 RawString* Function::BuildSignature(bool instantiate,
6748 NameVisibility name_visibility, 6644 NameVisibility name_visibility,
6749 const TypeArguments& instantiator) const { 6645 const TypeArguments& instantiator) const {
6750 Thread* thread = Thread::Current(); 6646 Thread* thread = Thread::Current();
6751 Zone* zone = thread->zone(); 6647 Zone* zone = thread->zone();
6752 GrowableHandlePtrArray<const String> pieces(zone, 4); 6648 GrowableHandlePtrArray<const String> pieces(zone, 4);
6753 String& name = String::Handle(zone); 6649 String& name = String::Handle(zone);
6754 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { 6650 if (!instantiate && !is_static() && (name_visibility == kInternalName)) {
6755 // Prefix the signature with its signature class and type parameters, if any 6651 // Prefix the signature with its scope class and type parameters, if any
6756 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the 6652 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the
6757 // signature class name is the alias name. 6653 // scope class name is the alias name.
6758 // The signature of static functions cannot be type parameterized. 6654 // The signature of static functions cannot be type parameterized.
6759 const Class& function_class = Class::Handle(zone, Owner()); 6655 const Class& scope_class = Class::Handle(zone, Owner());
6760 ASSERT(!function_class.IsNull()); 6656 ASSERT(!scope_class.IsNull());
6761 const TypeArguments& type_parameters = TypeArguments::Handle( 6657 if (scope_class.IsGeneric()) {
6762 zone, function_class.type_parameters()); 6658 const TypeArguments& type_parameters = TypeArguments::Handle(
6763 if (!type_parameters.IsNull()) { 6659 zone, scope_class.type_parameters());
6764 const String& function_class_name = 6660 const String& scope_class_name = String::Handle(zone, scope_class.Name());
6765 String::Handle(zone, function_class.Name()); 6661 pieces.Add(scope_class_name);
6766 pieces.Add(function_class_name);
6767 const intptr_t num_type_parameters = type_parameters.Length(); 6662 const intptr_t num_type_parameters = type_parameters.Length();
6768 pieces.Add(Symbols::LAngleBracket()); 6663 pieces.Add(Symbols::LAngleBracket());
6769 TypeParameter& type_parameter = TypeParameter::Handle(zone); 6664 TypeParameter& type_parameter = TypeParameter::Handle(zone);
6770 AbstractType& bound = AbstractType::Handle(zone); 6665 AbstractType& bound = AbstractType::Handle(zone);
6771 for (intptr_t i = 0; i < num_type_parameters; i++) { 6666 for (intptr_t i = 0; i < num_type_parameters; i++) {
6772 type_parameter ^= type_parameters.TypeAt(i); 6667 type_parameter ^= type_parameters.TypeAt(i);
6773 name = type_parameter.name(); 6668 name = type_parameter.name();
6774 pieces.Add(name); 6669 pieces.Add(name);
6775 bound = type_parameter.bound(); 6670 bound = type_parameter.bound();
6776 if (!bound.IsNull() && !bound.IsObjectType()) { 6671 if (!bound.IsNull() && !bound.IsObjectType()) {
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
7268 ASSERT(raw_ptr()->closure_ == Instance::null()); 7163 ASSERT(raw_ptr()->closure_ == Instance::null());
7269 StorePointer(&raw_ptr()->closure_, closure.raw()); 7164 StorePointer(&raw_ptr()->closure_, closure.raw());
7270 } 7165 }
7271 7166
7272 7167
7273 void ClosureData::set_parent_function(const Function& value) const { 7168 void ClosureData::set_parent_function(const Function& value) const {
7274 StorePointer(&raw_ptr()->parent_function_, value.raw()); 7169 StorePointer(&raw_ptr()->parent_function_, value.raw());
7275 } 7170 }
7276 7171
7277 7172
7278 void ClosureData::set_signature_class(const Class& value) const { 7173 void ClosureData::set_signature_type(const FunctionType& value) const {
7279 StorePointer(&raw_ptr()->signature_class_, value.raw()); 7174 StorePointer(&raw_ptr()->signature_type_, value.raw());
7280 } 7175 }
7281 7176
7282 7177
7283 RawClosureData* ClosureData::New() { 7178 RawClosureData* ClosureData::New() {
7284 ASSERT(Object::closure_data_class() != Class::null()); 7179 ASSERT(Object::closure_data_class() != Class::null());
7285 RawObject* raw = Object::Allocate(ClosureData::kClassId, 7180 RawObject* raw = Object::Allocate(ClosureData::kClassId,
7286 ClosureData::InstanceSize(), 7181 ClosureData::InstanceSize(),
7287 Heap::kOld); 7182 Heap::kOld);
7288 return reinterpret_cast<RawClosureData*>(raw); 7183 return reinterpret_cast<RawClosureData*>(raw);
7289 } 7184 }
(...skipping 3231 matching lines...) Expand 10 before | Expand all | Expand 10 after
10521 if (ref) { 10416 if (ref) {
10522 return; 10417 return;
10523 } 10418 }
10524 jsobj.AddProperty("debuggable", IsDebuggable()); 10419 jsobj.AddProperty("debuggable", IsDebuggable());
10525 { 10420 {
10526 JSONArray jsarr(&jsobj, "classes"); 10421 JSONArray jsarr(&jsobj, "classes");
10527 ClassDictionaryIterator class_iter(*this); 10422 ClassDictionaryIterator class_iter(*this);
10528 Class& klass = Class::Handle(); 10423 Class& klass = Class::Handle();
10529 while (class_iter.HasNext()) { 10424 while (class_iter.HasNext()) {
10530 klass = class_iter.GetNextClass(); 10425 klass = class_iter.GetNextClass();
10531 if (!klass.IsCanonicalSignatureClass() && 10426 if (!klass.IsMixinApplication()) {
10532 !klass.IsMixinApplication()) {
10533 jsarr.AddValue(klass); 10427 jsarr.AddValue(klass);
10534 } 10428 }
10535 } 10429 }
10536 } 10430 }
10537 { 10431 {
10538 JSONArray jsarr(&jsobj, "dependencies"); 10432 JSONArray jsarr(&jsobj, "dependencies");
10539 10433
10540 Array& ports = Array::Handle(); 10434 Array& ports = Array::Handle();
10541 Namespace& ns = Namespace::Handle(); 10435 Namespace& ns = Namespace::Handle();
10542 Library& target = Library::Handle(); 10436 Library& target = Library::Handle();
(...skipping 3845 matching lines...) Expand 10 before | Expand all | Expand 10 after
14388 14282
14389 14283
14390 intptr_t SubtypeTestCache::NumberOfChecks() const { 14284 intptr_t SubtypeTestCache::NumberOfChecks() const {
14391 NoSafepointScope no_safepoint; 14285 NoSafepointScope no_safepoint;
14392 // Do not count the sentinel; 14286 // Do not count the sentinel;
14393 return (Smi::Value(cache()->ptr()->length_) / kTestEntryLength) - 1; 14287 return (Smi::Value(cache()->ptr()->length_) / kTestEntryLength) - 1;
14394 } 14288 }
14395 14289
14396 14290
14397 void SubtypeTestCache::AddCheck( 14291 void SubtypeTestCache::AddCheck(
14398 intptr_t instance_class_id, 14292 const Object& instance_class_id_or_function,
14399 const TypeArguments& instance_type_arguments, 14293 const TypeArguments& instance_type_arguments,
14400 const TypeArguments& instantiator_type_arguments, 14294 const TypeArguments& instantiator_type_arguments,
14401 const Bool& test_result) const { 14295 const Bool& test_result) const {
14402 intptr_t old_num = NumberOfChecks(); 14296 intptr_t old_num = NumberOfChecks();
14403 Array& data = Array::Handle(cache()); 14297 Array& data = Array::Handle(cache());
14404 intptr_t new_len = data.Length() + kTestEntryLength; 14298 intptr_t new_len = data.Length() + kTestEntryLength;
14405 data = Array::Grow(data, new_len); 14299 data = Array::Grow(data, new_len);
14406 set_cache(data); 14300 set_cache(data);
14407 intptr_t data_pos = old_num * kTestEntryLength; 14301 intptr_t data_pos = old_num * kTestEntryLength;
14408 data.SetAt(data_pos + kInstanceClassId, 14302 data.SetAt(data_pos + kInstanceClassIdOrFunction,
14409 Smi::Handle(Smi::New(instance_class_id))); 14303 instance_class_id_or_function);
14410 data.SetAt(data_pos + kInstanceTypeArguments, instance_type_arguments); 14304 data.SetAt(data_pos + kInstanceTypeArguments, instance_type_arguments);
14411 data.SetAt(data_pos + kInstantiatorTypeArguments, 14305 data.SetAt(data_pos + kInstantiatorTypeArguments,
14412 instantiator_type_arguments); 14306 instantiator_type_arguments);
14413 data.SetAt(data_pos + kTestResult, test_result); 14307 data.SetAt(data_pos + kTestResult, test_result);
14414 } 14308 }
14415 14309
14416 14310
14417 void SubtypeTestCache::GetCheck(intptr_t ix, 14311 void SubtypeTestCache::GetCheck(intptr_t ix,
14418 intptr_t* instance_class_id, 14312 Object* instance_class_id_or_function,
14419 TypeArguments* instance_type_arguments, 14313 TypeArguments* instance_type_arguments,
14420 TypeArguments* instantiator_type_arguments, 14314 TypeArguments* instantiator_type_arguments,
14421 Bool* test_result) const { 14315 Bool* test_result) const {
14422 Array& data = Array::Handle(cache()); 14316 Array& data = Array::Handle(cache());
14423 intptr_t data_pos = ix * kTestEntryLength; 14317 intptr_t data_pos = ix * kTestEntryLength;
14424 *instance_class_id = 14318 *instance_class_id_or_function =
14425 Smi::Value(Smi::RawCast(data.At(data_pos + kInstanceClassId))); 14319 data.At(data_pos + kInstanceClassIdOrFunction);
14426 *instance_type_arguments ^= data.At(data_pos + kInstanceTypeArguments); 14320 *instance_type_arguments ^= data.At(data_pos + kInstanceTypeArguments);
14427 *instantiator_type_arguments ^= 14321 *instantiator_type_arguments ^=
14428 data.At(data_pos + kInstantiatorTypeArguments); 14322 data.At(data_pos + kInstantiatorTypeArguments);
14429 *test_result ^= data.At(data_pos + kTestResult); 14323 *test_result ^= data.At(data_pos + kTestResult);
14430 } 14324 }
14431 14325
14432 14326
14433 const char* SubtypeTestCache::ToCString() const { 14327 const char* SubtypeTestCache::ToCString() const {
14434 return "SubtypeTestCache"; 14328 return "SubtypeTestCache";
14435 } 14329 }
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
14974 // Create a canonical object in old space. 14868 // Create a canonical object in old space.
14975 result ^= Object::Clone(result, Heap::kOld); 14869 result ^= Object::Clone(result, Heap::kOld);
14976 } 14870 }
14977 ASSERT(result.IsOld()); 14871 ASSERT(result.IsOld());
14978 cls.InsertCanonicalConstant(index, result); 14872 cls.InsertCanonicalConstant(index, result);
14979 result.SetCanonical(); 14873 result.SetCanonical();
14980 return result.raw(); 14874 return result.raw();
14981 } 14875 }
14982 14876
14983 14877
14984 RawType* Instance::GetType() const { 14878 RawAbstractType* Instance::GetType() const {
14985 if (IsNull()) { 14879 if (IsNull()) {
14986 return Type::NullType(); 14880 return Type::NullType();
14987 } 14881 }
14988 const Class& cls = Class::Handle(clazz()); 14882 const Class& cls = Class::Handle(clazz());
14883 if (cls.IsClosureClass()) {
14884 const Function& signature =
14885 Function::Handle(Closure::Cast(*this).function());
14886 FunctionType& type = FunctionType::Handle(signature.SignatureType());
14887 if (type.scope_class() == cls.raw()) {
14888 // Type is not parameterized.
14889 if (!type.IsCanonical()) {
14890 type ^= type.Canonicalize();
14891 signature.SetSignatureType(type);
14892 }
14893 return type.raw();
14894 }
14895 const Class& scope_cls = Class::Handle(type.scope_class());
14896 ASSERT(scope_cls.NumTypeArguments() > 0);
14897 TypeArguments& type_arguments = TypeArguments::Handle(GetTypeArguments());
14898 type = FunctionType::New(
14899 scope_cls, type_arguments, signature, Token::kNoSourcePos);
14900 type.SetIsFinalized();
14901 type ^= type.Canonicalize();
14902 return type.raw();
14903 }
14989 Type& type = Type::Handle(); 14904 Type& type = Type::Handle();
14990 if (!cls.IsGeneric()) { 14905 if (!cls.IsGeneric()) {
14991 type = cls.CanonicalType(); 14906 type = cls.CanonicalType();
14992 } 14907 }
14993 if (type.IsNull()) { 14908 if (type.IsNull()) {
14994 TypeArguments& type_arguments = TypeArguments::Handle(); 14909 TypeArguments& type_arguments = TypeArguments::Handle();
14995 if (cls.NumTypeArguments() > 0) { 14910 if (cls.NumTypeArguments() > 0) {
14996 type_arguments = GetTypeArguments(); 14911 type_arguments = GetTypeArguments();
14997 } 14912 }
14998 type = Type::New(cls, type_arguments, Token::kNoSourcePos); 14913 type = Type::New(cls, type_arguments, Token::kNoSourcePos);
(...skipping 28 matching lines...) Expand all
15027 Error* bound_error) const { 14942 Error* bound_error) const {
15028 ASSERT(other.IsFinalized()); 14943 ASSERT(other.IsFinalized());
15029 ASSERT(!other.IsDynamicType()); 14944 ASSERT(!other.IsDynamicType());
15030 ASSERT(!other.IsMalformed()); 14945 ASSERT(!other.IsMalformed());
15031 ASSERT(!other.IsMalbounded()); 14946 ASSERT(!other.IsMalbounded());
15032 if (other.IsVoidType()) { 14947 if (other.IsVoidType()) {
15033 return false; 14948 return false;
15034 } 14949 }
15035 Zone* zone = Thread::Current()->zone(); 14950 Zone* zone = Thread::Current()->zone();
15036 const Class& cls = Class::Handle(zone, clazz()); 14951 const Class& cls = Class::Handle(zone, clazz());
14952 if (cls.IsClosureClass()) {
14953 if (other.IsObjectType() || other.IsDartFunctionType()) {
14954 return true;
14955 }
14956 Function& other_signature = Function::Handle(zone);
14957 TypeArguments& other_type_arguments = TypeArguments::Handle(zone);
14958 // Note that we may encounter a bound error in checked mode.
14959 if (!other.IsInstantiated()) {
14960 const AbstractType& instantiated_other = AbstractType::Handle(
14961 zone, other.InstantiateFrom(other_instantiator, bound_error));
14962 if ((bound_error != NULL) && !bound_error->IsNull()) {
14963 ASSERT(Isolate::Current()->flags().type_checks());
14964 return false;
14965 }
14966 if (instantiated_other.IsDynamicType() ||
14967 instantiated_other.IsObjectType() ||
14968 instantiated_other.IsDartFunctionType()) {
14969 return true;
14970 }
14971 if (!instantiated_other.IsFunctionType()) {
14972 return false;
14973 }
14974 other_signature = FunctionType::Cast(instantiated_other).signature();
14975 other_type_arguments = instantiated_other.arguments();
14976 } else {
14977 if (!other.IsFunctionType()) {
14978 return false;
14979 }
14980 other_signature = FunctionType::Cast(other).signature();
14981 other_type_arguments = other.arguments();
14982 }
14983 const Function& signature =
14984 Function::Handle(zone, Closure::Cast(*this).function());
14985 const TypeArguments& type_arguments =
14986 TypeArguments::Handle(zone, GetTypeArguments());
14987 return signature.IsSubtypeOf(type_arguments,
14988 other_signature,
14989 other_type_arguments,
14990 bound_error,
14991 Heap::kOld);
14992 }
15037 TypeArguments& type_arguments = TypeArguments::Handle(zone); 14993 TypeArguments& type_arguments = TypeArguments::Handle(zone);
15038 if (cls.NumTypeArguments() > 0) { 14994 if (cls.NumTypeArguments() > 0) {
15039 type_arguments = GetTypeArguments(); 14995 type_arguments = GetTypeArguments();
15040 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical()); 14996 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical());
15041 // The number of type arguments in the instance must be greater or equal to 14997 // The number of type arguments in the instance must be greater or equal to
15042 // the number of type arguments expected by the instance class. 14998 // the number of type arguments expected by the instance class.
15043 // A discrepancy is allowed for closures, which borrow the type argument 14999 // A discrepancy is allowed for closures, which borrow the type argument
15044 // vector of their instantiator, which may be of a subclass of the class 15000 // vector of their instantiator, which may be of a subclass of the class
15045 // defining the closure. Truncating the vector to the correct length on 15001 // defining the closure. Truncating the vector to the correct length on
15046 // instantiation is unnecessary. The vector may therefore be longer. 15002 // instantiation is unnecessary. The vector may therefore be longer.
15047 // Also, an optimization reuses the type argument vector of the instantiator 15003 // Also, an optimization reuses the type argument vector of the instantiator
15048 // of generic instances when its layout is compatible. 15004 // of generic instances when its layout is compatible.
15049 ASSERT(type_arguments.IsNull() || 15005 ASSERT(type_arguments.IsNull() ||
15050 (type_arguments.Length() >= cls.NumTypeArguments())); 15006 (type_arguments.Length() >= cls.NumTypeArguments()));
15051 } 15007 }
15052 Class& other_class = Class::Handle(zone); 15008 Class& other_class = Class::Handle(zone);
15053 TypeArguments& other_type_arguments = TypeArguments::Handle(zone); 15009 TypeArguments& other_type_arguments = TypeArguments::Handle(zone);
15010 AbstractType& instantiated_other = AbstractType::Handle(zone, other.raw());
15054 // Note that we may encounter a bound error in checked mode. 15011 // Note that we may encounter a bound error in checked mode.
15055 if (!other.IsInstantiated()) { 15012 if (!other.IsInstantiated()) {
15056 const AbstractType& instantiated_other = AbstractType::Handle( 15013 instantiated_other = other.InstantiateFrom(other_instantiator, bound_error);
15057 zone, other.InstantiateFrom(other_instantiator, bound_error));
15058 if ((bound_error != NULL) && !bound_error->IsNull()) { 15014 if ((bound_error != NULL) && !bound_error->IsNull()) {
15059 ASSERT(Isolate::Current()->flags().type_checks()); 15015 ASSERT(Isolate::Current()->flags().type_checks());
15060 return false; 15016 return false;
15061 } 15017 }
15062 other_class = instantiated_other.type_class(); 15018 if (instantiated_other.IsTypeRef()) {
15063 other_type_arguments = instantiated_other.arguments(); 15019 instantiated_other = TypeRef::Cast(instantiated_other).type();
15064 } else { 15020 }
15065 other_class = other.type_class(); 15021 if (instantiated_other.IsDynamicType()) {
15066 other_type_arguments = other.arguments(); 15022 return true;
15023 }
15067 } 15024 }
15025 other_type_arguments = instantiated_other.arguments();
15026 const bool other_is_dart_function = instantiated_other.IsDartFunctionType();
15027 if (other_is_dart_function || instantiated_other.IsFunctionType()) {
15028 // Check if this instance understands a call() method of a compatible type.
15029 Function& call =
15030 Function::Handle(zone, cls.LookupDynamicFunction(Symbols::Call()));
15031 if (call.IsNull()) {
15032 // Walk up the super_class chain.
15033 Class& super_cls = Class::Handle(zone, cls.SuperClass());
15034 while (!super_cls.IsNull() && call.IsNull()) {
15035 call = super_cls.LookupDynamicFunction(Symbols::Call());
15036 super_cls = super_cls.SuperClass();
15037 }
15038 }
15039 if (!call.IsNull()) {
15040 if (other_is_dart_function) {
15041 return true;
15042 }
15043 const Function& other_signature = Function::Handle(
15044 zone, FunctionType::Cast(instantiated_other).signature());
15045 if (call.IsSubtypeOf(type_arguments,
15046 other_signature,
15047 other_type_arguments,
15048 bound_error,
15049 Heap::kOld)) {
15050 return true;
15051 }
15052 }
15053 }
15054 if (!instantiated_other.IsType()) {
15055 return false;
15056 }
15057 other_class = instantiated_other.type_class();
15068 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments, 15058 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments,
15069 bound_error, Heap::kOld); 15059 bound_error, Heap::kOld);
15070 } 15060 }
15071 15061
15072 15062
15073 bool Instance::OperatorEquals(const Instance& other) const { 15063 bool Instance::OperatorEquals(const Instance& other) const {
15074 // TODO(koda): Optimize for all builtin classes and all classes 15064 // TODO(koda): Optimize for all builtin classes and all classes
15075 // that do not override operator==. 15065 // that do not override operator==.
15076 return DartLibraryCalls::Equals(*this, other) == Object::bool_true().raw(); 15066 return DartLibraryCalls::Equals(*this, other) == Object::bool_true().raw();
15077 } 15067 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
15123 native_fields = TypedData::New(kIntPtrCid, NumNativeFields()); 15113 native_fields = TypedData::New(kIntPtrCid, NumNativeFields());
15124 StorePointer(NativeFieldsAddr(), native_fields.raw()); 15114 StorePointer(NativeFieldsAddr(), native_fields.raw());
15125 } 15115 }
15126 for (uint16_t i = 0; i < num_native_fields; i++) { 15116 for (uint16_t i = 0; i < num_native_fields; i++) {
15127 intptr_t byte_offset = i * sizeof(intptr_t); 15117 intptr_t byte_offset = i * sizeof(intptr_t);
15128 TypedData::Cast(native_fields).SetIntPtr(byte_offset, field_values[i]); 15118 TypedData::Cast(native_fields).SetIntPtr(byte_offset, field_values[i]);
15129 } 15119 }
15130 } 15120 }
15131 15121
15132 15122
15133 bool Instance::IsClosure() const {
15134 const Class& cls = Class::Handle(clazz());
15135 return cls.IsSignatureClass();
15136 }
15137
15138
15139 bool Instance::IsCallable(Function* function) const { 15123 bool Instance::IsCallable(Function* function) const {
15140 Class& cls = Class::Handle(clazz()); 15124 Class& cls = Class::Handle(clazz());
15141 if (cls.IsSignatureClass()) { 15125 if (cls.IsClosureClass()) {
15142 if (function != NULL) { 15126 if (function != NULL) {
15143 *function = Closure::function(*this); 15127 *function = Closure::Cast(*this).function();
15144 } 15128 }
15145 return true; 15129 return true;
15146 } 15130 }
15147 // Try to resolve a "call" method. 15131 // Try to resolve a "call" method.
15148 Function& call_function = Function::Handle(); 15132 Function& call_function = Function::Handle();
15149 do { 15133 do {
15150 call_function = cls.LookupDynamicFunction(Symbols::Call()); 15134 call_function = cls.LookupDynamicFunction(Symbols::Call());
15151 if (!call_function.IsNull()) { 15135 if (!call_function.IsNull()) {
15152 if (function != NULL) { 15136 if (function != NULL) {
15153 *function = call_function.raw(); 15137 *function = call_function.raw();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
15238 return "transition_sentinel"; 15222 return "transition_sentinel";
15239 } else if (raw() == Object::unknown_constant().raw()) { 15223 } else if (raw() == Object::unknown_constant().raw()) {
15240 return "unknown_constant"; 15224 return "unknown_constant";
15241 } else if (raw() == Object::non_constant().raw()) { 15225 } else if (raw() == Object::non_constant().raw()) {
15242 return "non_constant"; 15226 return "non_constant";
15243 } else if (Thread::Current()->no_safepoint_scope_depth() > 0) { 15227 } else if (Thread::Current()->no_safepoint_scope_depth() > 0) {
15244 // Can occur when running disassembler. 15228 // Can occur when running disassembler.
15245 return "Instance"; 15229 return "Instance";
15246 } else { 15230 } else {
15247 if (IsClosure()) { 15231 if (IsClosure()) {
15248 return Closure::ToCString(*this); 15232 return Closure::Cast(*this).ToCString();
15249 } 15233 }
15250 const Class& cls = Class::Handle(clazz()); 15234 const Class& cls = Class::Handle(clazz());
15251 TypeArguments& type_arguments = TypeArguments::Handle(); 15235 TypeArguments& type_arguments = TypeArguments::Handle();
15252 const intptr_t num_type_arguments = cls.NumTypeArguments(); 15236 const intptr_t num_type_arguments = cls.NumTypeArguments();
15253 if (num_type_arguments > 0) { 15237 if (num_type_arguments > 0) {
15254 type_arguments = GetTypeArguments(); 15238 type_arguments = GetTypeArguments();
15255 } 15239 }
15256 const Type& type = 15240 const Type& type =
15257 Type::Handle(Type::New(cls, type_arguments, Token::kNoSourcePos)); 15241 Type::Handle(Type::New(cls, type_arguments, Token::kNoSourcePos));
15258 const String& type_name = String::Handle(type.UserVisibleName()); 15242 const String& type_name = String::Handle(type.UserVisibleName());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
15323 15307
15324 PrintSharedInstanceJSON(&jsobj, ref); 15308 PrintSharedInstanceJSON(&jsobj, ref);
15325 if (IsClosure()) { 15309 if (IsClosure()) {
15326 jsobj.AddProperty("kind", "Closure"); 15310 jsobj.AddProperty("kind", "Closure");
15327 } else { 15311 } else {
15328 jsobj.AddProperty("kind", "PlainInstance"); 15312 jsobj.AddProperty("kind", "PlainInstance");
15329 } 15313 }
15330 jsobj.AddServiceId(*this); 15314 jsobj.AddServiceId(*this);
15331 if (IsClosure()) { 15315 if (IsClosure()) {
15332 jsobj.AddProperty("closureFunction", 15316 jsobj.AddProperty("closureFunction",
15333 Function::Handle(Closure::function(*this))); 15317 Function::Handle(Closure::Cast(*this).function()));
15334 jsobj.AddProperty("closureContext", 15318 jsobj.AddProperty("closureContext",
15335 Context::Handle(Closure::context(*this))); 15319 Context::Handle(Closure::Cast(*this).context()));
15336 } 15320 }
15337 if (ref) { 15321 if (ref) {
15338 return; 15322 return;
15339 } 15323 }
15340 if (IsClosure()) { 15324 if (IsClosure()) {
15341 Debugger* debugger = Isolate::Current()->debugger(); 15325 Debugger* debugger = Isolate::Current()->debugger();
15342 Breakpoint* bpt = debugger->BreakpointAtActivation(*this); 15326 Breakpoint* bpt = debugger->BreakpointAtActivation(*this);
15343 if (bpt != NULL) { 15327 if (bpt != NULL) {
15344 jsobj.AddProperty("_activationBreakpoint", bpt); 15328 jsobj.AddProperty("_activationBreakpoint", bpt);
15345 } 15329 }
15346 } 15330 }
15347 } 15331 }
15348 15332
15349 15333
15350 bool AbstractType::IsResolved() const { 15334 bool AbstractType::IsResolved() const {
15351 // AbstractType is an abstract class. 15335 // AbstractType is an abstract class.
15352 UNREACHABLE(); 15336 UNREACHABLE();
15353 return false; 15337 return false;
15354 } 15338 }
15355 15339
15356 15340
15341 void AbstractType::SetIsResolved() const {
15342 // AbstractType is an abstract class.
15343 UNREACHABLE();
15344 }
15345
15346
15357 bool AbstractType::HasResolvedTypeClass() const { 15347 bool AbstractType::HasResolvedTypeClass() const {
15358 // AbstractType is an abstract class. 15348 // AbstractType is an abstract class.
15359 UNREACHABLE(); 15349 UNREACHABLE();
15360 return false; 15350 return false;
15361 } 15351 }
15362 15352
15363 15353
15364 RawClass* AbstractType::type_class() const { 15354 RawClass* AbstractType::type_class() const {
15365 // AbstractType is an abstract class. 15355 // AbstractType is an abstract class.
15366 UNREACHABLE(); 15356 UNREACHABLE();
15367 return Class::null(); 15357 return Class::null();
15368 } 15358 }
15369 15359
15370 15360
15371 RawUnresolvedClass* AbstractType::unresolved_class() const { 15361 RawUnresolvedClass* AbstractType::unresolved_class() const {
15372 // AbstractType is an abstract class. 15362 // AbstractType is an abstract class.
15373 UNREACHABLE(); 15363 UNREACHABLE();
15374 return UnresolvedClass::null(); 15364 return UnresolvedClass::null();
15375 } 15365 }
15376 15366
15377 15367
15378 RawTypeArguments* AbstractType::arguments() const { 15368 RawTypeArguments* AbstractType::arguments() const {
15379 // AbstractType is an abstract class. 15369 // AbstractType is an abstract class.
15380 UNREACHABLE(); 15370 UNREACHABLE();
15381 return NULL; 15371 return NULL;
15382 } 15372 }
15383 15373
15384 15374
15375 void AbstractType::set_arguments(const TypeArguments& value) const {
15376 // AbstractType is an abstract class.
15377 UNREACHABLE();
15378 }
15379
15385 intptr_t AbstractType::token_pos() const { 15380 intptr_t AbstractType::token_pos() const {
15386 // AbstractType is an abstract class. 15381 // AbstractType is an abstract class.
15387 UNREACHABLE(); 15382 UNREACHABLE();
15388 return -1; 15383 return -1;
15389 } 15384 }
15390 15385
15391 15386
15392 bool AbstractType::IsInstantiated(TrailPtr trail) const { 15387 bool AbstractType::IsInstantiated(TrailPtr trail) const {
15393 // AbstractType is an abstract class. 15388 // AbstractType is an abstract class.
15394 UNREACHABLE(); 15389 UNREACHABLE();
15395 return false; 15390 return false;
15396 } 15391 }
15397 15392
15398 15393
15399 bool AbstractType::IsFinalized() const { 15394 bool AbstractType::IsFinalized() const {
15400 // AbstractType is an abstract class. 15395 // AbstractType is an abstract class.
15401 UNREACHABLE(); 15396 UNREACHABLE();
15402 return false; 15397 return false;
15403 } 15398 }
15404 15399
15405 15400
15401 void AbstractType::SetIsFinalized() const {
15402 // AbstractType is an abstract class.
15403 UNREACHABLE();
15404 }
15405
15406
15406 bool AbstractType::IsBeingFinalized() const { 15407 bool AbstractType::IsBeingFinalized() const {
15407 // AbstractType is an abstract class. 15408 // AbstractType is an abstract class.
15408 UNREACHABLE(); 15409 UNREACHABLE();
15409 return false; 15410 return false;
15410 } 15411 }
15411 15412
15412 15413
15414 void AbstractType::SetIsBeingFinalized() const {
15415 // AbstractType is an abstract class.
15416 UNREACHABLE();
15417 }
15418
15419
15413 bool AbstractType::IsMalformed() const { 15420 bool AbstractType::IsMalformed() const {
15414 // AbstractType is an abstract class. 15421 // AbstractType is an abstract class.
15415 UNREACHABLE(); 15422 UNREACHABLE();
15416 return false; 15423 return false;
15417 } 15424 }
15418 15425
15419 15426
15420 bool AbstractType::IsMalbounded() const { 15427 bool AbstractType::IsMalbounded() const {
15421 // AbstractType is an abstract class. 15428 // AbstractType is an abstract class.
15422 UNREACHABLE(); 15429 UNREACHABLE();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
15557 if (IsTypeParameter()) { 15564 if (IsTypeParameter()) {
15558 return TypeParameter::Cast(*this).name(); 15565 return TypeParameter::Cast(*this).name();
15559 } 15566 }
15560 // If the type is still being finalized, we may be reporting an error about 15567 // If the type is still being finalized, we may be reporting an error about
15561 // a malformed type, so proceed with caution. 15568 // a malformed type, so proceed with caution.
15562 const TypeArguments& args = TypeArguments::Handle(zone, arguments()); 15569 const TypeArguments& args = TypeArguments::Handle(zone, arguments());
15563 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); 15570 const intptr_t num_args = args.IsNull() ? 0 : args.Length();
15564 String& class_name = String::Handle(zone); 15571 String& class_name = String::Handle(zone);
15565 intptr_t first_type_param_index; 15572 intptr_t first_type_param_index;
15566 intptr_t num_type_params; // Number of type parameters to print. 15573 intptr_t num_type_params; // Number of type parameters to print.
15567 if (HasResolvedTypeClass()) { 15574 Class& cls = Class::Handle(zone);
15568 const Class& cls = Class::Handle(zone, type_class()); 15575 if (IsFunctionType()) {
15576 cls = type_class();
15577 if (!cls.IsTypedefClass()) {
15578 const Function& signature_function = Function::Handle(
15579 zone, FunctionType::Cast(*this).signature());
15580 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) {
15581 return signature_function.UserVisibleSignature();
15582 }
15583 return signature_function.InstantiatedSignatureFrom(args,
15584 name_visibility);
15585 }
15586 class_name = cls.Name(); // Typedef name.
15587 // We may be reporting an error about a malformed function type. In that
15588 // case, avoid instantiating the signature, since it may cause divergence.
15589 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) {
15590 return class_name.raw();
15591 }
15592 // Print the name of a typedef as a regular, possibly parameterized, class.
15593 } else if (HasResolvedTypeClass()) {
15594 cls = type_class();
15595 }
15596 if (!cls.IsNull()) {
15569 if (IsResolved() || !cls.IsMixinApplication()) { 15597 if (IsResolved() || !cls.IsMixinApplication()) {
15570 // Do not print the full vector, but only the declared type parameters. 15598 // Do not print the full vector, but only the declared type parameters.
15571 num_type_params = cls.NumTypeParameters(); 15599 num_type_params = cls.NumTypeParameters();
15572 } else { 15600 } else {
15573 // Do not print the type parameters of an unresolved mixin application, 15601 // Do not print the type parameters of an unresolved mixin application,
15574 // since it would prematurely trigger the application of the mixin type. 15602 // since it would prematurely trigger the application of the mixin type.
15575 num_type_params = 0; 15603 num_type_params = 0;
15576 } 15604 }
15577 if (name_visibility == kInternalName) { 15605 if (name_visibility == kInternalName) {
15578 class_name = cls.Name(); 15606 class_name = cls.Name();
(...skipping 17 matching lines...) Expand all
15596 } 15624 }
15597 } else { 15625 } else {
15598 // The actual type argument vector can be longer than necessary, because 15626 // The actual type argument vector can be longer than necessary, because
15599 // of type optimizations. 15627 // of type optimizations.
15600 if (IsFinalized() && cls.is_type_finalized()) { 15628 if (IsFinalized() && cls.is_type_finalized()) {
15601 first_type_param_index = cls.NumTypeArguments() - num_type_params; 15629 first_type_param_index = cls.NumTypeArguments() - num_type_params;
15602 } else { 15630 } else {
15603 first_type_param_index = num_args - num_type_params; 15631 first_type_param_index = num_args - num_type_params;
15604 } 15632 }
15605 } 15633 }
15606 if (cls.IsSignatureClass()) {
15607 // We may be reporting an error about a malformed function type. In that
15608 // case, avoid instantiating the signature, since it may cause divergence.
15609 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) {
15610 return class_name.raw();
15611 }
15612 // To avoid divergence, print the name of a typedef (non-canonical
15613 // signature class) as a regular, possibly parameterized, class.
15614 if (cls.IsCanonicalSignatureClass()) {
15615 const Function& signature_function = Function::Handle(
15616 zone, cls.signature_function());
15617 // Signature classes have no super type, however, they take as many
15618 // type arguments as the owner class of their signature function (if it
15619 // is non static and generic, see Class::NumTypeArguments()). Therefore,
15620 // first_type_param_index may be greater than 0 here.
15621 return signature_function.InstantiatedSignatureFrom(args,
15622 name_visibility);
15623 }
15624 }
15625 } else { 15634 } else {
15626 const UnresolvedClass& cls = 15635 class_name = UnresolvedClass::Handle(zone, unresolved_class()).Name();
15627 UnresolvedClass::Handle(zone, unresolved_class());
15628 class_name = cls.Name();
15629 num_type_params = num_args; 15636 num_type_params = num_args;
15630 first_type_param_index = 0; 15637 first_type_param_index = 0;
15631 } 15638 }
15632 GrowableHandlePtrArray<const String> pieces(zone, 4); 15639 GrowableHandlePtrArray<const String> pieces(zone, 4);
15633 pieces.Add(class_name); 15640 pieces.Add(class_name);
15634 if ((num_type_params == 0) || 15641 if ((num_type_params == 0) ||
15635 args.IsRaw(first_type_param_index, num_type_params)) { 15642 args.IsRaw(first_type_param_index, num_type_params)) {
15636 // Do nothing. 15643 // Do nothing.
15637 } else { 15644 } else {
15638 const String& args_name = String::Handle(zone, 15645 const String& args_name = String::Handle(zone,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
15710 (type_class() == Type::Handle(Type::SmiType()).type_class()); 15717 (type_class() == Type::Handle(Type::SmiType()).type_class());
15711 } 15718 }
15712 15719
15713 15720
15714 bool AbstractType::IsStringType() const { 15721 bool AbstractType::IsStringType() const {
15715 return HasResolvedTypeClass() && 15722 return HasResolvedTypeClass() &&
15716 (type_class() == Type::Handle(Type::StringType()).type_class()); 15723 (type_class() == Type::Handle(Type::StringType()).type_class());
15717 } 15724 }
15718 15725
15719 15726
15720 bool AbstractType::IsFunctionType() const { 15727 bool AbstractType::IsDartFunctionType() const {
15721 return HasResolvedTypeClass() && 15728 return HasResolvedTypeClass() &&
15722 (type_class() == Type::Handle(Type::Function()).type_class()); 15729 (type_class() == Type::Handle(Type::Function()).type_class());
15723 } 15730 }
15724 15731
15725 15732
15726 bool AbstractType::TypeTest(TypeTestKind test_kind, 15733 bool AbstractType::TypeTest(TypeTestKind test_kind,
15727 const AbstractType& other, 15734 const AbstractType& other,
15728 Error* bound_error, 15735 Error* bound_error,
15729 Heap::Space space) const { 15736 Heap::Space space) const {
15730 ASSERT(IsFinalized()); 15737 ASSERT(IsFinalized());
(...skipping 17 matching lines...) Expand all
15748 } 15755 }
15749 return false; 15756 return false;
15750 } 15757 }
15751 if (other.IsMalbounded()) { 15758 if (other.IsMalbounded()) {
15752 ASSERT(Isolate::Current()->flags().type_checks()); 15759 ASSERT(Isolate::Current()->flags().type_checks());
15753 if ((bound_error != NULL) && bound_error->IsNull()) { 15760 if ((bound_error != NULL) && bound_error->IsNull()) {
15754 *bound_error = other.error(); 15761 *bound_error = other.error();
15755 } 15762 }
15756 return false; 15763 return false;
15757 } 15764 }
15765 if (other.IsObjectType() || other.IsDynamicType()) {
15766 return true;
15767 }
15758 if (IsBoundedType() || other.IsBoundedType()) { 15768 if (IsBoundedType() || other.IsBoundedType()) {
15759 if (Equals(other)) { 15769 if (Equals(other)) {
15760 return true; 15770 return true;
15761 } 15771 }
15762 // Redundant check if other type is equal to the upper bound of this type. 15772 // Redundant check if other type is equal to the upper bound of this type.
15763 if (IsBoundedType() && 15773 if (IsBoundedType() &&
15764 AbstractType::Handle(BoundedType::Cast(*this).bound()).Equals(other)) { 15774 AbstractType::Handle(BoundedType::Cast(*this).bound()).Equals(other)) {
15765 return true; 15775 return true;
15766 } 15776 }
15767 return false; // TODO(regis): We should return "maybe after instantiation". 15777 return false; // TODO(regis): We should return "maybe after instantiation".
15768 } 15778 }
15779 Zone* zone = Thread::Current()->zone();
15769 // Type parameters cannot be handled by Class::TypeTest(). 15780 // Type parameters cannot be handled by Class::TypeTest().
15770 // When comparing two uninstantiated function types, one returning type 15781 // When comparing two uninstantiated function types, one returning type
15771 // parameter K, the other returning type parameter V, we cannot assume that K 15782 // parameter K, the other returning type parameter V, we cannot assume that K
15772 // is a subtype of V, or vice versa. We only return true if K equals V, as 15783 // is a subtype of V, or vice versa. We only return true if K equals V, as
15773 // defined by TypeParameter::Equals. 15784 // defined by TypeParameter::Equals.
15774 // The same rule applies when checking the upper bound of a still 15785 // The same rule applies when checking the upper bound of a still
15775 // uninstantiated type at compile time. Returning false will defer the test 15786 // uninstantiated type at compile time. Returning false will defer the test
15776 // to run time. 15787 // to run time.
15777 // There are however some cases can be decided at compile time. 15788 // There are however some cases that can be decided at compile time.
15778 // For example, with class A<K, V extends K>, new A<T, T> called from within 15789 // For example, with class A<K, V extends K>, new A<T, T> called from within
15779 // a class B<T> will never require a run time bound check, even if T is 15790 // a class B<T> will never require a run time bound check, even if T is
15780 // uninstantiated at compile time. 15791 // uninstantiated at compile time.
15781 if (IsTypeParameter()) { 15792 if (IsTypeParameter()) {
15782 const TypeParameter& type_param = TypeParameter::Cast(*this); 15793 const TypeParameter& type_param = TypeParameter::Cast(*this);
15783 if (other.IsTypeParameter()) { 15794 if (other.IsTypeParameter()) {
15784 const TypeParameter& other_type_param = TypeParameter::Cast(other); 15795 const TypeParameter& other_type_param = TypeParameter::Cast(other);
15785 if (type_param.Equals(other_type_param)) { 15796 if (type_param.Equals(other_type_param)) {
15786 return true; 15797 return true;
15787 } 15798 }
15788 } 15799 }
15789 const AbstractType& bound = AbstractType::Handle(type_param.bound()); 15800 const AbstractType& bound = AbstractType::Handle(zone, type_param.bound());
15790 // We may be checking bounds at finalization time and can encounter 15801 // We may be checking bounds at finalization time and can encounter
15791 // a still unfinalized bound. Finalizing the bound here may lead to cycles. 15802 // a still unfinalized bound. Finalizing the bound here may lead to cycles.
15792 if (!bound.IsFinalized()) { 15803 if (!bound.IsFinalized()) {
15793 return false; // TODO(regis): Return "maybe after instantiation". 15804 return false; // TODO(regis): Return "maybe after instantiation".
15794 } 15805 }
15795 if (bound.IsMoreSpecificThan(other, bound_error)) { 15806 if (bound.IsMoreSpecificThan(other, bound_error)) {
15796 return true; 15807 return true;
15797 } 15808 }
15798 return false; // TODO(regis): We should return "maybe after instantiation". 15809 return false; // TODO(regis): We should return "maybe after instantiation".
15799 } 15810 }
15800 if (other.IsTypeParameter()) { 15811 if (other.IsTypeParameter()) {
15801 return false; // TODO(regis): We should return "maybe after instantiation". 15812 return false; // TODO(regis): We should return "maybe after instantiation".
15802 } 15813 }
15803 const Class& cls = Class::Handle(type_class()); 15814 const Class& type_cls = Class::Handle(zone, type_class());
15804 return cls.TypeTest(test_kind, 15815 // Function types cannot be handled by Class::TypeTest().
15805 TypeArguments::Handle(arguments()), 15816 const bool other_is_dart_function_type = other.IsDartFunctionType();
15806 Class::Handle(other.type_class()), 15817 if (other_is_dart_function_type || other.IsFunctionType()) {
15807 TypeArguments::Handle(other.arguments()), 15818 if (IsFunctionType()) {
15808 bound_error, 15819 if (other_is_dart_function_type) {
15809 space); 15820 return true;
15821 }
15822 const Function& other_fun =
15823 Function::Handle(zone, FunctionType::Cast(other).signature());
15824 // Check for two function types.
15825 const Function& fun =
15826 Function::Handle(zone, FunctionType::Cast(*this).signature());
15827 return fun.TypeTest(test_kind,
15828 TypeArguments::Handle(zone, arguments()),
15829 other_fun,
15830 TypeArguments::Handle(zone, other.arguments()),
15831 bound_error,
15832 space);
15833 }
15834 // Check if type S has a call() method of function type T.
15835 Function& function =
15836 Function::Handle(zone, type_cls.LookupDynamicFunction(Symbols::Call()));
15837 if (function.IsNull()) {
15838 // Walk up the super_class chain.
15839 Class& cls = Class::Handle(zone, type_cls.SuperClass());
15840 while (!cls.IsNull() && function.IsNull()) {
15841 function = cls.LookupDynamicFunction(Symbols::Call());
15842 cls = cls.SuperClass();
15843 }
15844 }
15845 if (!function.IsNull()) {
15846 if (other_is_dart_function_type ||
15847 function.TypeTest(test_kind,
15848 TypeArguments::Handle(zone, arguments()),
15849 Function::Handle(
15850 zone, FunctionType::Cast(other).signature()),
15851 TypeArguments::Handle(zone, other.arguments()),
15852 bound_error,
15853 space)) {
15854 return true;
15855 }
15856 }
15857 }
15858 if (IsFunctionType()) {
15859 return false;
15860 }
15861 return type_cls.TypeTest(test_kind,
15862 TypeArguments::Handle(zone, arguments()),
15863 Class::Handle(zone, other.type_class()),
15864 TypeArguments::Handle(zone, other.arguments()),
15865 bound_error,
15866 space);
15810 } 15867 }
15811 15868
15812 15869
15813 intptr_t AbstractType::Hash() const { 15870 intptr_t AbstractType::Hash() const {
15814 // AbstractType is an abstract class. 15871 // AbstractType is an abstract class.
15815 UNREACHABLE(); 15872 UNREACHABLE();
15816 return 0; 15873 return 0;
15817 } 15874 }
15818 15875
15819 15876
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
15929 ASSERT(!IsFinalized()); 15986 ASSERT(!IsFinalized());
15930 if (IsInstantiated()) { 15987 if (IsInstantiated()) {
15931 ASSERT(HasResolvedTypeClass()); 15988 ASSERT(HasResolvedTypeClass());
15932 set_type_state(RawType::kFinalizedInstantiated); 15989 set_type_state(RawType::kFinalizedInstantiated);
15933 } else { 15990 } else {
15934 set_type_state(RawType::kFinalizedUninstantiated); 15991 set_type_state(RawType::kFinalizedUninstantiated);
15935 } 15992 }
15936 } 15993 }
15937 15994
15938 15995
15939 void Type::ResetIsFinalized() const { 15996 void Type::SetIsBeingFinalized() const {
15940 ASSERT(IsFinalized());
15941 set_type_state(RawType::kBeingFinalized);
15942 SetIsFinalized();
15943 }
15944
15945
15946 void Type::set_is_being_finalized() const {
15947 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized()); 15997 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized());
15948 set_type_state(RawType::kBeingFinalized); 15998 set_type_state(RawType::kBeingFinalized);
15949 } 15999 }
15950 16000
15951 16001
15952 bool Type::IsMalformed() const { 16002 bool Type::IsMalformed() const {
15953 if (raw_ptr()->error_ == LanguageError::null()) { 16003 if (raw_ptr()->error_ == LanguageError::null()) {
15954 return false; 16004 return false;
15955 } 16005 }
15956 const LanguageError& type_error = LanguageError::Handle(error()); 16006 const LanguageError& type_error = LanguageError::Handle(error());
(...skipping 24 matching lines...) Expand all
15981 ASSERT(type_error.kind() == Report::kMalboundedType); 16031 ASSERT(type_error.kind() == Report::kMalboundedType);
15982 return Isolate::Current()->flags().type_checks(); 16032 return Isolate::Current()->flags().type_checks();
15983 } 16033 }
15984 16034
15985 16035
15986 void Type::set_error(const LanguageError& value) const { 16036 void Type::set_error(const LanguageError& value) const {
15987 StorePointer(&raw_ptr()->error_, value.raw()); 16037 StorePointer(&raw_ptr()->error_, value.raw());
15988 } 16038 }
15989 16039
15990 16040
15991 void Type::set_is_resolved() const { 16041 void Type::SetIsResolved() const {
15992 ASSERT(!IsResolved()); 16042 ASSERT(!IsResolved());
16043 // A Typedef is a FunctionType, not a type.
16044 ASSERT(!Class::Handle(type_class()).IsTypedefClass());
15993 set_type_state(RawType::kResolved); 16045 set_type_state(RawType::kResolved);
15994 } 16046 }
15995 16047
15996 16048
15997 bool Type::HasResolvedTypeClass() const { 16049 bool Type::HasResolvedTypeClass() const {
15998 const Object& type_class = Object::Handle(raw_ptr()->type_class_); 16050 const Object& type_class = Object::Handle(raw_ptr()->type_class_);
15999 return !type_class.IsNull() && type_class.IsClass(); 16051 return !type_class.IsNull() && type_class.IsClass();
16000 } 16052 }
16001 16053
16002 16054
(...skipping 17 matching lines...) Expand all
16020 ASSERT(!unresolved_class.IsNull()); 16072 ASSERT(!unresolved_class.IsNull());
16021 return unresolved_class.raw(); 16073 return unresolved_class.raw();
16022 #else 16074 #else
16023 ASSERT(!Object::Handle(raw_ptr()->type_class_).IsNull()); 16075 ASSERT(!Object::Handle(raw_ptr()->type_class_).IsNull());
16024 ASSERT(Object::Handle(raw_ptr()->type_class_).IsUnresolvedClass()); 16076 ASSERT(Object::Handle(raw_ptr()->type_class_).IsUnresolvedClass());
16025 return reinterpret_cast<RawUnresolvedClass*>(raw_ptr()->type_class_); 16077 return reinterpret_cast<RawUnresolvedClass*>(raw_ptr()->type_class_);
16026 #endif 16078 #endif
16027 } 16079 }
16028 16080
16029 16081
16030 RawTypeArguments* Type::arguments() const {
16031 return raw_ptr()->arguments_;
16032 }
16033
16034
16035 bool Type::IsInstantiated(TrailPtr trail) const { 16082 bool Type::IsInstantiated(TrailPtr trail) const {
16036 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) { 16083 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) {
16037 return true; 16084 return true;
16038 } 16085 }
16039 if (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated) { 16086 if (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated) {
16040 return false; 16087 return false;
16041 } 16088 }
16042 if (arguments() == TypeArguments::null()) { 16089 if (arguments() == TypeArguments::null()) {
16043 return true; 16090 return true;
16044 } 16091 }
16045 const TypeArguments& args = TypeArguments::Handle(arguments()); 16092 const TypeArguments& args = TypeArguments::Handle(arguments());
16046 intptr_t num_type_args = args.Length(); 16093 intptr_t num_type_args = args.Length();
16047 intptr_t len = num_type_args; // Check the full vector of type args. 16094 intptr_t len = num_type_args; // Check the full vector of type args.
16048 ASSERT(num_type_args > 0); 16095 ASSERT(num_type_args > 0);
16049 // This type is not instantiated if it refers to type parameters. 16096 // This type is not instantiated if it refers to type parameters.
16050 // This IsInstantiated() call may be invoked on an unresolved signature type.
16051 // Although this type may still be unresolved, the type parameters it may 16097 // Although this type may still be unresolved, the type parameters it may
16052 // refer to are resolved by definition. We can therefore return the correct 16098 // refer to are resolved by definition. We can therefore return the correct
16053 // result even for an unresolved type. We just need to look at all type 16099 // result even for an unresolved type. We just need to look at all type
16054 // arguments and not just at the type parameters. 16100 // arguments and not just at the type parameters.
16055 if (HasResolvedTypeClass()) { 16101 if (HasResolvedTypeClass()) {
16056 const Class& cls = Class::Handle(type_class()); 16102 const Class& cls = Class::Handle(type_class());
16057 len = cls.NumTypeArguments(); 16103 len = cls.NumTypeArguments();
16058 ASSERT(num_type_args >= len); // The vector may be longer than necessary. 16104 ASSERT(num_type_args >= len); // The vector may be longer than necessary.
16059 num_type_args = len; 16105 num_type_args = len;
16060 len = cls.NumTypeParameters(); // Check the type parameters only. 16106 len = cls.NumTypeParameters(); // Check the type parameters only.
(...skipping 26 matching lines...) Expand all
16087 ASSERT(IsRecursive()); 16133 ASSERT(IsRecursive());
16088 return instantiated_type.raw(); 16134 return instantiated_type.raw();
16089 } 16135 }
16090 // Note that the type class has to be resolved at this time, but not 16136 // Note that the type class has to be resolved at this time, but not
16091 // necessarily finalized yet. We may be checking bounds at compile time or 16137 // necessarily finalized yet. We may be checking bounds at compile time or
16092 // finalizing the type argument vector of a recursive type. 16138 // finalizing the type argument vector of a recursive type.
16093 const Class& cls = Class::Handle(zone, type_class()); 16139 const Class& cls = Class::Handle(zone, type_class());
16094 16140
16095 // This uninstantiated type is not modified, as it can be instantiated 16141 // This uninstantiated type is not modified, as it can be instantiated
16096 // with different instantiators. Allocate a new instantiated version of it. 16142 // with different instantiators. Allocate a new instantiated version of it.
16097 instantiated_type = Type::New(cls, TypeArguments::Handle(zone), token_pos()); 16143 instantiated_type =
16144 Type::New(cls, TypeArguments::Handle(zone), token_pos(), space);
16098 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments()); 16145 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments());
16099 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); 16146 ASSERT(type_arguments.Length() == cls.NumTypeArguments());
16100 if (type_arguments.IsRecursive()) { 16147 if (type_arguments.IsRecursive()) {
16101 AddOnlyBuddyToTrail(&trail, instantiated_type); 16148 AddOnlyBuddyToTrail(&trail, instantiated_type);
16102 } 16149 }
16103 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, 16150 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments,
16104 bound_error, 16151 bound_error,
16105 trail, 16152 trail,
16106 space); 16153 space);
16107 instantiated_type.set_arguments(type_arguments); 16154 instantiated_type.set_arguments(type_arguments);
16108 if (IsFinalized()) { 16155 if (IsFinalized()) {
16109 instantiated_type.SetIsFinalized(); 16156 instantiated_type.SetIsFinalized();
16110 } else { 16157 } else {
16111 instantiated_type.set_is_resolved(); 16158 instantiated_type.SetIsResolved();
16112 } 16159 }
16113 // Canonicalization is not part of instantiation. 16160 // Canonicalization is not part of instantiation.
16114 return instantiated_type.raw(); 16161 return instantiated_type.raw();
16115 } 16162 }
16116 16163
16117 16164
16118 bool Type::IsEquivalent(const Instance& other, TrailPtr trail) const { 16165 bool Type::IsEquivalent(const Instance& other, TrailPtr trail) const {
16119 ASSERT(!IsNull()); 16166 ASSERT(!IsNull());
16120 if (raw() == other.raw()) { 16167 if (raw() == other.raw()) {
16121 return true; 16168 return true;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
16203 16250
16204 RawAbstractType* Type::CloneUnfinalized() const { 16251 RawAbstractType* Type::CloneUnfinalized() const {
16205 ASSERT(IsResolved()); 16252 ASSERT(IsResolved());
16206 if (IsFinalized()) { 16253 if (IsFinalized()) {
16207 return raw(); 16254 return raw();
16208 } 16255 }
16209 ASSERT(!IsMalformed()); // Malformed types are finalized. 16256 ASSERT(!IsMalformed()); // Malformed types are finalized.
16210 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. 16257 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization.
16211 TypeArguments& type_args = TypeArguments::Handle(arguments()); 16258 TypeArguments& type_args = TypeArguments::Handle(arguments());
16212 type_args = type_args.CloneUnfinalized(); 16259 type_args = type_args.CloneUnfinalized();
16213 const Class& type_cls = Class::Handle(type_class()); 16260 const Type& clone = Type::Handle(
16214 const Type& clone = Type::Handle(Type::New(type_cls, type_args, token_pos())); 16261 Type::New(Class::Handle(type_class()), type_args, token_pos()));
16215 clone.set_is_resolved(); 16262 clone.SetIsResolved();
16216 return clone.raw(); 16263 return clone.raw();
16217 } 16264 }
16218 16265
16219 16266
16220 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner, 16267 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner,
16221 TrailPtr trail) const { 16268 TrailPtr trail) const {
16222 ASSERT(IsFinalized()); 16269 ASSERT(IsFinalized());
16223 ASSERT(!IsMalformed()); 16270 ASSERT(!IsMalformed());
16224 if (IsInstantiated()) { 16271 if (IsInstantiated()) {
16225 return raw(); 16272 return raw();
(...skipping 21 matching lines...) Expand all
16247 16294
16248 RawAbstractType* Type::Canonicalize(TrailPtr trail) const { 16295 RawAbstractType* Type::Canonicalize(TrailPtr trail) const {
16249 ASSERT(IsFinalized()); 16296 ASSERT(IsFinalized());
16250 if (IsCanonical() || IsMalformed()) { 16297 if (IsCanonical() || IsMalformed()) {
16251 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld()); 16298 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld());
16252 return this->raw(); 16299 return this->raw();
16253 } 16300 }
16254 Thread* thread = Thread::Current(); 16301 Thread* thread = Thread::Current();
16255 Zone* zone = thread->zone(); 16302 Zone* zone = thread->zone();
16256 Isolate* isolate = thread->isolate(); 16303 Isolate* isolate = thread->isolate();
16257 Type& type = Type::Handle(zone); 16304 AbstractType& type = Type::Handle(zone);
16258 const Class& cls = Class::Handle(zone, type_class()); 16305 const Class& cls = Class::Handle(zone, type_class());
16306 ASSERT(!cls.IsTypedefClass()); // This type should be a FunctionType.
16259 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) { 16307 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) {
16260 return Object::dynamic_type().raw(); 16308 return Object::dynamic_type().raw();
16261 } 16309 }
16262 // Fast canonical lookup/registry for simple types. 16310 // Fast canonical lookup/registry for simple types.
16263 if (!cls.IsGeneric()) { 16311 if (!cls.IsGeneric() && !cls.IsClosureClass()) {
16264 type = cls.CanonicalType(); 16312 type = cls.CanonicalType();
16265 if (type.IsNull()) { 16313 if (type.IsNull()) {
16266 ASSERT(!cls.raw()->IsVMHeapObject() || (isolate == Dart::vm_isolate())); 16314 ASSERT(!cls.raw()->IsVMHeapObject() || (isolate == Dart::vm_isolate()));
16267 // Canonicalize the type arguments of the supertype, if any. 16315 // Canonicalize the type arguments of the supertype, if any.
16268 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); 16316 TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16269 type_args = type_args.Canonicalize(trail); 16317 type_args = type_args.Canonicalize(trail);
16270 set_arguments(type_args); 16318 set_arguments(type_args);
16271 type = cls.CanonicalType(); // May be set while canonicalizing type args. 16319 type = cls.CanonicalType(); // May be set while canonicalizing type args.
16272 if (type.IsNull()) { 16320 if (type.IsNull()) {
16273 cls.set_canonical_types(*this); 16321 cls.set_canonical_types(*this);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
16338 ASSERT((index == length) || ((index == 1) && (length == 0))); 16386 ASSERT((index == length) || ((index == 1) && (length == 0)));
16339 const intptr_t new_length = (length > 64) ? 16387 const intptr_t new_length = (length > 64) ?
16340 (length + 64) : 16388 (length + 64) :
16341 ((length == 0) ? 2 : (length * 2)); 16389 ((length == 0) ? 2 : (length * 2));
16342 const Array& new_canonical_types = Array::Handle( 16390 const Array& new_canonical_types = Array::Handle(
16343 zone, Array::Grow(canonical_types, new_length, Heap::kOld)); 16391 zone, Array::Grow(canonical_types, new_length, Heap::kOld));
16344 cls.set_canonical_types(new_canonical_types); 16392 cls.set_canonical_types(new_canonical_types);
16345 canonical_types = new_canonical_types.raw(); 16393 canonical_types = new_canonical_types.raw();
16346 } 16394 }
16347 canonical_types.SetAt(index, *this); 16395 canonical_types.SetAt(index, *this);
16348 if ((index == 1) && cls.IsCanonicalSignatureClass()) {
16349 canonical_types.SetAt(0, *this); // Also set canonical signature type at 0.
16350 #ifdef DEBUG
16351 // Verify that the first canonical type is the signature type by checking
16352 // that the type argument vector of the canonical type ends with the
16353 // uninstantiated type parameters of the signature class. Note that these
16354 // type parameters may be bounded if the super class of the owner class
16355 // declares bounds.
16356 // The signature type is finalized during class finalization, before the
16357 // optimizer may canonicalize instantiated function types of the same
16358 // signature class.
16359 // Although the signature class extends class Instance, the type arguments
16360 // of the super class of the owner class of its signature function will be
16361 // prepended to the type argument vector during class finalization.
16362 const TypeArguments& type_params =
16363 TypeArguments::Handle(zone, cls.type_parameters());
16364 const intptr_t num_type_params = cls.NumTypeParameters();
16365 const intptr_t num_type_args = cls.NumTypeArguments();
16366 AbstractType& type_arg = AbstractType::Handle(zone);
16367 TypeParameter& type_param = TypeParameter::Handle(zone);
16368 for (intptr_t i = 0; i < num_type_params; i++) {
16369 type_arg = type_args.TypeAt(num_type_args - num_type_params + i);
16370 while (type_arg.IsBoundedType()) {
16371 type_arg = BoundedType::Cast(type_arg).type();
16372 }
16373 type_param ^= type_params.TypeAt(i);
16374 ASSERT(type_arg.Equals(type_param));
16375 }
16376 #endif
16377 }
16378 ASSERT(IsOld()); 16396 ASSERT(IsOld());
16379 ASSERT(type_args.IsNull() || type_args.IsOld()); 16397 ASSERT(type_args.IsNull() || type_args.IsOld());
16380 SetCanonical(); 16398 SetCanonical();
16381 return this->raw(); 16399 return this->raw();
16382 } 16400 }
16383 16401
16384 16402
16385 intptr_t Type::Hash() const { 16403 intptr_t Type::Hash() const {
16386 ASSERT(IsFinalized()); 16404 ASSERT(IsFinalized());
16387 uint32_t result = 1; 16405 uint32_t result = 1;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
16484 if (ref) { 16502 if (ref) {
16485 return; 16503 return;
16486 } 16504 }
16487 const TypeArguments& typeArgs = TypeArguments::Handle(arguments()); 16505 const TypeArguments& typeArgs = TypeArguments::Handle(arguments());
16488 if (!typeArgs.IsNull()) { 16506 if (!typeArgs.IsNull()) {
16489 jsobj.AddProperty("typeArguments", typeArgs); 16507 jsobj.AddProperty("typeArguments", typeArgs);
16490 } 16508 }
16491 } 16509 }
16492 16510
16493 16511
16512 void FunctionType::SetIsFinalized() const {
16513 ASSERT(!IsFinalized());
16514 if (IsInstantiated()) {
16515 set_type_state(RawFunctionType::kFinalizedInstantiated);
16516 } else {
16517 set_type_state(RawFunctionType::kFinalizedUninstantiated);
16518 }
16519 }
16520
16521
16522 void FunctionType::ResetIsFinalized() const {
16523 ASSERT(IsFinalized());
16524 set_type_state(RawFunctionType::kBeingFinalized);
16525 SetIsFinalized();
16526 }
16527
16528
16529 void FunctionType::SetIsBeingFinalized() const {
16530 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized());
16531 set_type_state(RawFunctionType::kBeingFinalized);
16532 }
16533
16534
16535 bool FunctionType::IsMalformed() const {
16536 if (raw_ptr()->error_ == LanguageError::null()) {
16537 return false;
16538 }
16539 const LanguageError& type_error = LanguageError::Handle(error());
16540 return type_error.kind() == Report::kMalformedType;
16541 }
16542
16543
16544 bool FunctionType::IsMalbounded() const {
16545 if (!Isolate::Current()->flags().type_checks()) {
16546 return false;
16547 }
16548 if (raw_ptr()->error_ == LanguageError::null()) {
16549 return false;
16550 }
16551 const LanguageError& type_error = LanguageError::Handle(error());
16552 return type_error.kind() == Report::kMalboundedType;
16553 }
16554
16555
16556 bool FunctionType::IsMalformedOrMalbounded() const {
16557 if (raw_ptr()->error_ == LanguageError::null()) {
16558 return false;
16559 }
16560 const LanguageError& type_error = LanguageError::Handle(error());
16561 if (type_error.kind() == Report::kMalformedType) {
16562 return true;
16563 }
16564 ASSERT(type_error.kind() == Report::kMalboundedType);
16565 return Isolate::Current()->flags().type_checks();
16566 }
16567
16568
16569 void FunctionType::set_error(const LanguageError& value) const {
16570 StorePointer(&raw_ptr()->error_, value.raw());
16571 }
16572
16573
16574 void FunctionType::SetIsResolved() const {
16575 ASSERT(!IsResolved());
16576 set_type_state(RawFunctionType::kResolved);
16577 }
16578
16579
16580 bool FunctionType::IsInstantiated(TrailPtr trail) const {
16581 if (raw_ptr()->type_state_ == RawFunctionType::kFinalizedInstantiated) {
16582 return true;
16583 }
16584 if (raw_ptr()->type_state_ == RawFunctionType::kFinalizedUninstantiated) {
16585 return false;
16586 }
16587 if (arguments() == TypeArguments::null()) {
16588 return true;
16589 }
16590 const Class& scope_cls = Class::Handle(scope_class());
16591 if (!scope_cls.IsGeneric()) {
16592 ASSERT(scope_cls.IsClosureClass() || scope_cls.IsTypedefClass());
16593 ASSERT(arguments() == TypeArguments::null());
16594 return true;
16595 }
16596 const TypeArguments& type_arguments = TypeArguments::Handle(arguments());
16597 const intptr_t num_type_args = scope_cls.NumTypeArguments();
16598 const intptr_t num_type_params = scope_cls.NumTypeParameters();
16599 // The vector may be longer than necessary. An empty vector is handled above.
16600 ASSERT(type_arguments.Length() >= num_type_args);
16601 return
16602 (num_type_params == 0) ||
16603 type_arguments.IsSubvectorInstantiated(num_type_args - num_type_params,
16604 num_type_params);
16605 }
16606
16607
16608 RawAbstractType* FunctionType::InstantiateFrom(
16609 const TypeArguments& instantiator_type_arguments,
16610 Error* bound_error,
16611 TrailPtr trail,
16612 Heap::Space space) const {
16613 Zone* zone = Thread::Current()->zone();
16614 ASSERT(IsFinalized() || IsBeingFinalized());
16615 ASSERT(!IsInstantiated());
16616 ASSERT(!IsMalformed()); // FunctionType cannot be malformed.
16617 // Instantiating this type with its own type arguments as instantiator can
16618 // occur during finalization and bounds checking. Return the type unchanged.
16619 if (arguments() == instantiator_type_arguments.raw()) {
16620 return raw();
16621 }
16622 // If this type is recursive, we may already be instantiating it.
16623 FunctionType& instantiated_type = FunctionType::Handle(zone);
16624 instantiated_type ^= OnlyBuddyInTrail(trail);
16625 if (!instantiated_type.IsNull()) {
16626 ASSERT(IsRecursive());
16627 return instantiated_type.raw();
16628 }
16629 // Note that the scope class has to be resolved at this time, but not
16630 // necessarily finalized yet. We may be checking bounds at compile time or
16631 // finalizing the type argument vector of a recursive type.
16632 const Class& cls = Class::Handle(zone, scope_class());
16633
16634 // This uninstantiated type is not modified, as it can be instantiated
16635 // with different instantiators. Allocate a new instantiated version of it.
16636 instantiated_type =
16637 FunctionType::New(cls,
16638 TypeArguments::Handle(zone),
16639 Function::Handle(zone, signature()),
16640 token_pos(),
16641 space);
16642 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments());
16643 ASSERT(type_arguments.Length() == cls.NumTypeArguments());
16644 if (type_arguments.IsRecursive()) {
16645 AddOnlyBuddyToTrail(&trail, instantiated_type);
16646 }
16647 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments,
16648 bound_error,
16649 trail,
16650 space);
16651 instantiated_type.set_arguments(type_arguments);
16652 if (IsFinalized()) {
16653 instantiated_type.SetIsFinalized();
16654 } else {
16655 instantiated_type.SetIsResolved();
16656 }
16657 // Canonicalization is not part of instantiation.
16658 return instantiated_type.raw();
16659 }
16660
16661
16662 bool FunctionType::IsEquivalent(const Instance& other, TrailPtr trail) const {
16663 ASSERT(!IsNull());
16664 if (raw() == other.raw()) {
16665 return true;
16666 }
16667 if (!other.IsFunctionType()) {
16668 return false;
16669 }
16670 const FunctionType& other_type = FunctionType::Cast(other);
16671 ASSERT(IsResolved() && other_type.IsResolved());
16672 if (IsMalformed() || other_type.IsMalformed()) {
16673 return false;
16674 }
16675 if (scope_class() != other_type.scope_class()) {
16676 return false;
16677 }
16678 if ((arguments() == other_type.arguments()) &&
16679 (signature() == other_type.signature())) {
16680 return true;
16681 }
16682 if (!IsFinalized() || !other_type.IsFinalized()) {
16683 return false;
16684 }
16685
16686 // We do not instantiate the types of the signature. This happens on demand
16687 // at runtime during a type test.
16688 // Therefore, equal function types must have equal type arguments.
16689 Thread* thread = Thread::Current();
16690 Zone* zone = thread->zone();
16691 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16692 const TypeArguments& other_type_args = TypeArguments::Handle(
16693 zone, other_type.arguments());
16694 if (!type_args.Equals(other_type_args)) {
16695 return false;
16696 }
16697
16698 // Type arguments are equal.
16699 // Equal function types must have equal signature types and equal optional
16700 // named arguments.
16701 if (signature() == other_type.signature()) {
16702 return true;
16703 }
16704 const Function& sig_fun = Function::Handle(zone, signature());
16705 const Function& other_sig_fun = Function::Handle(
16706 zone, other_type.signature());
16707
16708 // Compare number of function parameters.
16709 const intptr_t num_fixed_params = sig_fun.num_fixed_parameters();
16710 const intptr_t other_num_fixed_params = other_sig_fun.num_fixed_parameters();
16711 if (num_fixed_params != other_num_fixed_params) {
16712 return false;
16713 }
16714 const intptr_t num_opt_pos_params = sig_fun.NumOptionalPositionalParameters();
16715 const intptr_t other_num_opt_pos_params =
16716 other_sig_fun.NumOptionalPositionalParameters();
16717 if (num_opt_pos_params != other_num_opt_pos_params) {
16718 return false;
16719 }
16720 const intptr_t num_opt_named_params = sig_fun.NumOptionalNamedParameters();
16721 const intptr_t other_num_opt_named_params =
16722 other_sig_fun.NumOptionalNamedParameters();
16723 if (num_opt_named_params != other_num_opt_named_params) {
16724 return false;
16725 }
16726 const intptr_t num_ignored_params = sig_fun.NumImplicitParameters();
16727 const intptr_t other_num_ignored_params =
16728 other_sig_fun.NumImplicitParameters();
16729 if (num_ignored_params != other_num_ignored_params) {
16730 return false;
16731 }
16732 AbstractType& param_type = Type::Handle(zone);
16733 AbstractType& other_param_type = Type::Handle(zone);
16734 // Check the result type.
16735 param_type = sig_fun.result_type();
16736 other_param_type = other_sig_fun.result_type();
16737 if (!param_type.Equals(other_param_type)) {
16738 return false;
16739 }
16740 // Check the types of all parameters.
16741 const intptr_t num_params = sig_fun.NumParameters();
16742 ASSERT(other_sig_fun.NumParameters() == num_params);
16743 for (intptr_t i = 0; i < num_params; i++) {
16744 param_type = sig_fun.ParameterTypeAt(i);
16745 other_param_type = other_sig_fun.ParameterTypeAt(i);
16746 if (!param_type.Equals(other_param_type)) {
16747 return false;
16748 }
16749 }
16750 // Check the names and types of optional named parameters.
16751 if (num_opt_named_params == 0) {
16752 return true;
16753 }
16754 for (intptr_t i = num_fixed_params; i < num_params; i++) {
16755 if (sig_fun.ParameterNameAt(i) != other_sig_fun.ParameterNameAt(i)) {
16756 return false;
16757 }
16758 }
16759 return true;
16760 }
16761
16762
16763 bool FunctionType::IsRecursive() const {
16764 return TypeArguments::Handle(arguments()).IsRecursive();
16765 }
16766
16767
16768 RawAbstractType* FunctionType::CloneUnfinalized() const {
16769 ASSERT(IsResolved());
16770 if (IsFinalized()) {
16771 return raw();
16772 }
16773 ASSERT(!IsMalformed()); // Malformed types are finalized.
16774 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization.
16775 TypeArguments& type_args = TypeArguments::Handle(arguments());
16776 type_args = type_args.CloneUnfinalized();
16777 const FunctionType& clone = FunctionType::Handle(
16778 FunctionType::New(Class::Handle(scope_class()),
16779 type_args,
16780 Function::Handle(signature()),
16781 token_pos()));
16782 clone.SetIsResolved();
16783 return clone.raw();
16784 }
16785
16786
16787 RawAbstractType* FunctionType::CloneUninstantiated(const Class& new_owner,
16788 TrailPtr trail) const {
16789 ASSERT(IsFinalized());
16790 ASSERT(!IsMalformed());
16791 if (IsInstantiated()) {
16792 return raw();
16793 }
16794 // We may recursively encounter a type already being cloned, because we clone
16795 // the upper bounds of its uninstantiated type arguments in the same pass.
16796 FunctionType& clone = FunctionType::Handle();
16797 clone ^= OnlyBuddyInTrail(trail);
16798 if (!clone.IsNull()) {
16799 return clone.raw();
16800 }
16801 clone = FunctionType::New(Class::Handle(scope_class()),
16802 TypeArguments::Handle(),
16803 Function::Handle(signature()),
16804 token_pos());
16805 TypeArguments& type_args = TypeArguments::Handle(arguments());
16806 // Upper bounds of uninstantiated type arguments may form a cycle.
16807 if (type_args.IsRecursive() || !type_args.IsInstantiated()) {
16808 AddOnlyBuddyToTrail(&trail, clone);
16809 }
16810 type_args = type_args.CloneUninstantiated(new_owner, trail);
16811 clone.set_arguments(type_args);
16812 clone.SetIsFinalized();
16813 return clone.raw();
16814 }
16815
16816
16817 RawAbstractType* FunctionType::Canonicalize(TrailPtr trail) const {
16818 ASSERT(IsFinalized());
16819 if (IsCanonical() || IsMalformed()) {
16820 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld());
16821 return this->raw();
16822 }
16823 Thread* thread = Thread::Current();
16824 Zone* zone = thread->zone();
16825 AbstractType& type = Type::Handle(zone);
16826 const Class& scope_cls = Class::Handle(zone, type_class());
16827 Array& canonical_types = Array::Handle(zone);
16828 canonical_types ^= scope_cls.canonical_types();
16829 if (canonical_types.IsNull()) {
16830 canonical_types = empty_array().raw();
16831 }
16832 intptr_t length = canonical_types.Length();
16833 // Linear search to see whether this type is already present in the
16834 // list of canonicalized types.
16835 // TODO(asiva): Try to re-factor this lookup code to make sharing
16836 // easy between the 4 versions of this loop.
16837 intptr_t index = 1; // Slot 0 is reserved for CanonicalType().
16838 while (index < length) {
16839 type ^= canonical_types.At(index);
16840 if (type.IsNull()) {
16841 break;
16842 }
16843 ASSERT(type.IsFinalized());
16844 if (this->Equals(type)) {
16845 ASSERT(type.IsCanonical());
16846 return type.raw();
16847 }
16848 index++;
16849 }
16850 // The type was not found in the table. It is not canonical yet.
16851
16852 // Canonicalize the type arguments.
16853 TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16854 // In case the type is first canonicalized at runtime, its type argument
16855 // vector may be longer than necessary. This is not an issue.
16856 ASSERT(type_args.IsNull() ||
16857 (type_args.Length() >= scope_cls.NumTypeArguments()));
16858 type_args = type_args.Canonicalize(trail);
16859 set_arguments(type_args);
16860
16861 // Replace the actual function by a signature function.
16862 const Function& fun = Function::Handle(zone, signature());
16863 if (!fun.IsSignatureFunction()) {
16864 Function& sig_fun =
16865 Function::Handle(zone,
16866 Function::NewSignatureFunction(scope_cls,
16867 Token::kNoSourcePos));
16868 type = fun.result_type();
16869 type = type.Canonicalize(trail);
16870 sig_fun.set_result_type(type);
16871 const intptr_t num_params = fun.NumParameters();
16872 sig_fun.set_num_fixed_parameters(fun.num_fixed_parameters());
16873 sig_fun.SetNumOptionalParameters(fun.NumOptionalParameters(),
16874 fun.HasOptionalPositionalParameters());
16875 sig_fun.set_parameter_types(Array::Handle(Array::New(num_params,
16876 Heap::kOld)));
16877 for (intptr_t i = 0; i < num_params; i++) {
16878 type = fun.ParameterTypeAt(i);
16879 type = type.Canonicalize(trail);
16880 sig_fun.SetParameterTypeAt(i, type);
16881 }
16882 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names()));
16883 set_signature(sig_fun);
16884 }
16885
16886 // Canonicalizing the type arguments and the signature may have changed the
16887 // index, may have grown the table, or may even have canonicalized this type.
16888 canonical_types ^= scope_cls.canonical_types();
16889 if (canonical_types.IsNull()) {
16890 canonical_types = empty_array().raw();
16891 }
16892 length = canonical_types.Length();
16893 while (index < length) {
16894 type ^= canonical_types.At(index);
16895 if (type.IsNull()) {
16896 break;
16897 }
16898 ASSERT(type.IsFinalized());
16899 if (this->Equals(type)) {
16900 ASSERT(type.IsCanonical());
16901 return type.raw();
16902 }
16903 index++;
16904 }
16905
16906 // The type needs to be added to the list. Grow the list if it is full.
16907 if (index >= length) {
16908 ASSERT((index == length) || ((index == 1) && (length == 0)));
16909 const intptr_t new_length = (length > 64) ?
16910 (length + 64) :
16911 ((length == 0) ? 2 : (length * 2));
16912 const Array& new_canonical_types = Array::Handle(
16913 zone, Array::Grow(canonical_types, new_length, Heap::kOld));
16914 scope_cls.set_canonical_types(new_canonical_types);
16915 canonical_types = new_canonical_types.raw();
16916 }
16917 canonical_types.SetAt(index, *this);
16918 ASSERT(IsOld());
16919 ASSERT(type_args.IsNull() || type_args.IsOld());
16920 SetCanonical();
16921 return this->raw();
16922 }
16923
16924
16925 intptr_t FunctionType::Hash() const {
16926 ASSERT(IsFinalized());
16927 uint32_t result = 1;
16928 if (IsMalformed()) return result;
16929 result = CombineHashes(result, Class::Handle(scope_class()).id());
16930 result = CombineHashes(result, TypeArguments::Handle(arguments()).Hash());
16931 const Function& sig_fun = Function::Handle(signature());
16932 AbstractType& type = AbstractType::Handle(sig_fun.result_type());
16933 result = CombineHashes(result, type.Hash());
16934 result = CombineHashes(result, sig_fun.NumOptionalPositionalParameters());
16935 const intptr_t num_params = sig_fun.NumParameters();
16936 for (intptr_t i = 0; i < num_params; i++) {
16937 type = sig_fun.ParameterTypeAt(i);
16938 result = CombineHashes(result, type.Hash());
16939 }
16940 if (sig_fun.NumOptionalNamedParameters() > 0) {
16941 String& param_name = String::Handle();
16942 for (intptr_t i = sig_fun.num_fixed_parameters(); i < num_params; i++) {
16943 param_name = sig_fun.ParameterNameAt(i);
16944 result = CombineHashes(result, param_name.Hash());
16945 }
16946 }
16947 return FinalizeHash(result);
16948 }
16949
16950
16951 void FunctionType::set_scope_class(const Class& value) const {
16952 ASSERT(!value.IsNull());
16953 StorePointer(&raw_ptr()->scope_class_, value.raw());
16954 }
16955
16956
16957 void FunctionType::set_arguments(const TypeArguments& value) const {
16958 StorePointer(&raw_ptr()->arguments_, value.raw());
16959 }
16960
16961
16962 void FunctionType::set_signature(const Function& value) const {
16963 StorePointer(&raw_ptr()->signature_, value.raw());
16964 }
16965
16966
16967 RawFunctionType* FunctionType::New(Heap::Space space) {
16968 RawObject* raw = Object::Allocate(FunctionType::kClassId,
16969 FunctionType::InstanceSize(),
16970 space);
16971 return reinterpret_cast<RawFunctionType*>(raw);
16972 }
16973
16974
16975 RawFunctionType* FunctionType::New(const Class& clazz,
16976 const TypeArguments& arguments,
16977 const Function& signature,
16978 intptr_t token_pos,
16979 Heap::Space space) {
16980 const FunctionType& result = FunctionType::Handle(FunctionType::New(space));
16981 result.set_scope_class(clazz);
16982 result.set_arguments(arguments);
16983 result.set_signature(signature);
16984 result.set_token_pos(token_pos);
16985 result.StoreNonPointer(&result.raw_ptr()->type_state_,
16986 RawFunctionType::kAllocated);
16987 return result.raw();
16988 }
16989
16990
16991 void FunctionType::set_token_pos(intptr_t token_pos) const {
16992 ASSERT(!Token::IsClassifying(token_pos));
16993 StoreNonPointer(&raw_ptr()->token_pos_, token_pos);
16994 }
16995
16996
16997 void FunctionType::set_type_state(int8_t state) const {
16998 ASSERT((state >= RawFunctionType::kAllocated) &&
16999 (state <= RawFunctionType::kFinalizedUninstantiated));
17000 StoreNonPointer(&raw_ptr()->type_state_, state);
17001 }
17002
17003
17004 const char* FunctionType::ToCString() const {
17005 const char* unresolved = IsResolved() ? "" : "Unresolved ";
17006 const Class& scope_cls = Class::Handle(scope_class());
17007 const TypeArguments& type_arguments = TypeArguments::Handle(arguments());
17008 const Function& signature_function = Function::Handle(signature());
17009 const String& signature_string = String::Handle(
17010 signature_function.InstantiatedSignatureFrom(type_arguments,
17011 kInternalName));
17012 if (scope_cls.IsClosureClass()) {
17013 ASSERT(arguments() == TypeArguments::null());
17014 return OS::SCreate(
17015 Thread::Current()->zone(),
17016 "%sFunctionType: %s", unresolved, signature_string.ToCString());
17017 }
17018 const char* class_name = String::Handle(scope_cls.Name()).ToCString();
17019 const char* args_cstr =
17020 type_arguments.IsNull() ? "null" : type_arguments.ToCString();
17021 return OS::SCreate(
17022 Thread::Current()->zone(),
17023 "%s FunctionType: %s (scope_cls: %s, args: %s)",
17024 unresolved,
17025 signature_string.ToCString(),
17026 class_name,
17027 args_cstr);
17028 }
17029
17030
17031 void FunctionType::PrintJSONImpl(JSONStream* stream, bool ref) const {
17032 JSONObject jsobj(stream);
17033 PrintSharedInstanceJSON(&jsobj, ref);
17034 jsobj.AddProperty("kind", "FunctionType");
17035 if (IsCanonical()) {
17036 const Class& scope_cls = Class::Handle(scope_class());
17037 intptr_t id = scope_cls.FindCanonicalTypeIndex(*this);
17038 ASSERT(id >= 0);
17039 intptr_t cid = scope_cls.id();
17040 jsobj.AddFixedServiceId("classes/%" Pd "/types/%" Pd "", cid, id);
17041 jsobj.AddProperty("scopeClass", scope_cls);
17042 } else {
17043 jsobj.AddServiceId(*this);
17044 }
17045 const String& user_name = String::Handle(PrettyName());
17046 const String& vm_name = String::Handle(Name());
17047 AddNameProperties(&jsobj, user_name, vm_name);
17048 if (ref) {
17049 return;
17050 }
17051 const TypeArguments& typeArgs = TypeArguments::Handle(arguments());
17052 if (!typeArgs.IsNull()) {
17053 jsobj.AddProperty("typeArguments", typeArgs);
17054 }
17055 }
17056
17057
16494 bool TypeRef::IsInstantiated(TrailPtr trail) const { 17058 bool TypeRef::IsInstantiated(TrailPtr trail) const {
16495 if (TestAndAddToTrail(&trail)) { 17059 if (TestAndAddToTrail(&trail)) {
16496 return true; 17060 return true;
16497 } 17061 }
16498 return AbstractType::Handle(type()).IsInstantiated(trail); 17062 return AbstractType::Handle(type()).IsInstantiated(trail);
16499 } 17063 }
16500 17064
16501 17065
16502 bool TypeRef::IsEquivalent(const Instance& other, TrailPtr trail) const { 17066 bool TypeRef::IsEquivalent(const Instance& other, TrailPtr trail) const {
16503 if (raw() == other.raw()) { 17067 if (raw() == other.raw()) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
16547 AbstractType& cloned_ref_type = AbstractType::Handle(); 17111 AbstractType& cloned_ref_type = AbstractType::Handle();
16548 cloned_ref_type = ref_type.CloneUninstantiated(new_owner, trail); 17112 cloned_ref_type = ref_type.CloneUninstantiated(new_owner, trail);
16549 ASSERT(!cloned_ref_type.IsTypeRef()); 17113 ASSERT(!cloned_ref_type.IsTypeRef());
16550 cloned_type_ref = TypeRef::New(cloned_ref_type); 17114 cloned_type_ref = TypeRef::New(cloned_ref_type);
16551 AddOnlyBuddyToTrail(&trail, cloned_type_ref); 17115 AddOnlyBuddyToTrail(&trail, cloned_type_ref);
16552 return cloned_type_ref.raw(); 17116 return cloned_type_ref.raw();
16553 } 17117 }
16554 17118
16555 17119
16556 void TypeRef::set_type(const AbstractType& value) const { 17120 void TypeRef::set_type(const AbstractType& value) const {
16557 ASSERT(value.HasResolvedTypeClass()); 17121 ASSERT(value.IsFunctionType() || value.HasResolvedTypeClass());
16558 ASSERT(!value.IsTypeRef()); 17122 ASSERT(!value.IsTypeRef());
16559 StorePointer(&raw_ptr()->type_, value.raw()); 17123 StorePointer(&raw_ptr()->type_, value.raw());
16560 } 17124 }
16561 17125
16562 17126
16563 // A TypeRef cannot be canonical by definition. Only its referenced type can be. 17127 // A TypeRef cannot be canonical by definition. Only its referenced type can be.
16564 // Consider the type Derived, where class Derived extends Base<Derived>. 17128 // Consider the type Derived, where class Derived extends Base<Derived>.
16565 // The first type argument of its flattened type argument vector is Derived, 17129 // The first type argument of its flattened type argument vector is Derived,
16566 // represented by a TypeRef pointing to itself. 17130 // represented by a TypeRef pointing to itself.
16567 RawAbstractType* TypeRef::Canonicalize(TrailPtr trail) const { 17131 RawAbstractType* TypeRef::Canonicalize(TrailPtr trail) const {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
16659 const String& user_name = String::Handle(PrettyName()); 17223 const String& user_name = String::Handle(PrettyName());
16660 const String& vm_name = String::Handle(Name()); 17224 const String& vm_name = String::Handle(Name());
16661 AddNameProperties(&jsobj, user_name, vm_name); 17225 AddNameProperties(&jsobj, user_name, vm_name);
16662 if (ref) { 17226 if (ref) {
16663 return; 17227 return;
16664 } 17228 }
16665 jsobj.AddProperty("targetType", AbstractType::Handle(type())); 17229 jsobj.AddProperty("targetType", AbstractType::Handle(type()));
16666 } 17230 }
16667 17231
16668 17232
16669 void TypeParameter::set_is_finalized() const { 17233 void TypeParameter::SetIsFinalized() const {
16670 ASSERT(!IsFinalized()); 17234 ASSERT(!IsFinalized());
16671 set_type_state(RawTypeParameter::kFinalizedUninstantiated); 17235 set_type_state(RawTypeParameter::kFinalizedUninstantiated);
16672 } 17236 }
16673 17237
16674 17238
16675 bool TypeParameter::IsEquivalent(const Instance& other, TrailPtr trail) const { 17239 bool TypeParameter::IsEquivalent(const Instance& other, TrailPtr trail) const {
16676 if (raw() == other.raw()) { 17240 if (raw() == other.raw()) {
16677 return true; 17241 return true;
16678 } 17242 }
16679 if (other.IsTypeRef()) { 17243 if (other.IsTypeRef()) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
16809 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail); 17373 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail);
16810 const Class& old_owner = Class::Handle(parameterized_class()); 17374 const Class& old_owner = Class::Handle(parameterized_class());
16811 const intptr_t new_index = index() + 17375 const intptr_t new_index = index() +
16812 new_owner.NumTypeArguments() - old_owner.NumTypeArguments(); 17376 new_owner.NumTypeArguments() - old_owner.NumTypeArguments();
16813 const TypeParameter& clone = TypeParameter::Handle( 17377 const TypeParameter& clone = TypeParameter::Handle(
16814 TypeParameter::New(new_owner, 17378 TypeParameter::New(new_owner,
16815 new_index, 17379 new_index,
16816 String::Handle(name()), 17380 String::Handle(name()),
16817 upper_bound, 17381 upper_bound,
16818 token_pos())); 17382 token_pos()));
16819 clone.set_is_finalized(); 17383 clone.SetIsFinalized();
16820 return clone.raw(); 17384 return clone.raw();
16821 } 17385 }
16822 17386
16823 17387
16824 intptr_t TypeParameter::Hash() const { 17388 intptr_t TypeParameter::Hash() const {
16825 ASSERT(IsFinalized()); 17389 ASSERT(IsFinalized());
16826 uint32_t result = Class::Handle(parameterized_class()).id(); 17390 uint32_t result = Class::Handle(parameterized_class()).id();
16827 // No need to include the hash of the bound, since the type parameter is fully 17391 // No need to include the hash of the bound, since the type parameter is fully
16828 // identified by its class and index. 17392 // identified by its class and index.
16829 result = CombineHashes(result, index()); 17393 result = CombineHashes(result, index());
(...skipping 4656 matching lines...) Expand 10 before | Expand all | Expand 10 after
21486 const char* SendPort::ToCString() const { 22050 const char* SendPort::ToCString() const {
21487 return "SendPort"; 22051 return "SendPort";
21488 } 22052 }
21489 22053
21490 22054
21491 void SendPort::PrintJSONImpl(JSONStream* stream, bool ref) const { 22055 void SendPort::PrintJSONImpl(JSONStream* stream, bool ref) const {
21492 Instance::PrintJSONImpl(stream, ref); 22056 Instance::PrintJSONImpl(stream, ref);
21493 } 22057 }
21494 22058
21495 22059
21496 const char* Closure::ToCString(const Instance& closure) { 22060 const char* Closure::ToCString() const {
21497 const Function& fun = Function::Handle(Closure::function(closure)); 22061 const Function& fun = Function::Handle(function());
21498 const bool is_implicit_closure = fun.IsImplicitClosureFunction(); 22062 const bool is_implicit_closure = fun.IsImplicitClosureFunction();
21499 const char* fun_sig = String::Handle(fun.UserVisibleSignature()).ToCString(); 22063 const char* fun_sig = String::Handle(fun.UserVisibleSignature()).ToCString();
21500 const char* from = is_implicit_closure ? " from " : ""; 22064 const char* from = is_implicit_closure ? " from " : "";
21501 const char* fun_desc = is_implicit_closure ? fun.ToCString() : ""; 22065 const char* fun_desc = is_implicit_closure ? fun.ToCString() : "";
21502 return OS::SCreate(Thread::Current()->zone(), 22066 return OS::SCreate(Thread::Current()->zone(),
21503 "Closure: %s%s%s", fun_sig, from, fun_desc); 22067 "Closure: %s%s%s", fun_sig, from, fun_desc);
21504 } 22068 }
21505 22069
21506 22070
21507 RawInstance* Closure::New(const Function& function, 22071 void Closure::PrintJSONImpl(JSONStream* stream, bool ref) const {
21508 const Context& context, 22072 Instance::PrintJSONImpl(stream, ref);
21509 Heap::Space space) { 22073 }
21510 const Class& cls = Class::Handle(function.signature_class()); 22074
21511 ASSERT(cls.instance_size() == Closure::InstanceSize()); 22075
21512 Instance& result = Instance::Handle(); 22076 RawClosure* Closure::New(const Function& function,
22077 const Context& context,
22078 Heap::Space space) {
22079 Closure& result = Closure::Handle();
21513 { 22080 {
21514 RawObject* raw = Object::Allocate(cls.id(), Closure::InstanceSize(), space); 22081 RawObject* raw = Object::Allocate(Closure::kClassId,
22082 Closure::InstanceSize(),
22083 space);
21515 NoSafepointScope no_safepoint; 22084 NoSafepointScope no_safepoint;
21516 result ^= raw; 22085 result ^= raw;
22086 result.StorePointer(&result.raw_ptr()->function_, function.raw());
22087 result.StorePointer(&result.raw_ptr()->context_, context.raw());
21517 } 22088 }
21518 Closure::set_function(result, function);
21519 Closure::set_context(result, context);
21520 return result.raw(); 22089 return result.raw();
21521 } 22090 }
21522 22091
21523 22092
22093 RawClosure* Closure::New() {
22094 RawObject* raw = Object::Allocate(Closure::kClassId,
22095 Closure::InstanceSize(),
22096 Heap::kOld);
22097 return reinterpret_cast<RawClosure*>(raw);
22098 }
22099
22100
21524 intptr_t Stacktrace::Length() const { 22101 intptr_t Stacktrace::Length() const {
21525 const Array& code_array = Array::Handle(raw_ptr()->code_array_); 22102 const Array& code_array = Array::Handle(raw_ptr()->code_array_);
21526 return code_array.Length(); 22103 return code_array.Length();
21527 } 22104 }
21528 22105
21529 22106
21530 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const { 22107 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const {
21531 const Code& code = Code::Handle(CodeAtFrame(frame_index)); 22108 const Code& code = Code::Handle(CodeAtFrame(frame_index));
21532 return code.IsNull() ? Function::null() : code.function(); 22109 return code.IsNull() ? Function::null() : code.function();
21533 } 22110 }
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
22127 return tag_label.ToCString(); 22704 return tag_label.ToCString();
22128 } 22705 }
22129 22706
22130 22707
22131 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 22708 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
22132 Instance::PrintJSONImpl(stream, ref); 22709 Instance::PrintJSONImpl(stream, ref);
22133 } 22710 }
22134 22711
22135 22712
22136 } // namespace dart 22713 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698