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

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: 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
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 Scanner::kNoSourcePos)); 1968 Scanner::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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
2450 // resolved, which is checked by the type_class() call on the super type. 2428 // resolved, which is checked by the type_class() call on the super type.
2451 // Note that calling type_class() on a MixinAppType fails. 2429 // Note that calling type_class() on a MixinAppType fails.
2452 Thread* thread = Thread::Current(); 2430 Thread* thread = Thread::Current();
2453 Zone* zone = thread->zone(); 2431 Zone* zone = thread->zone();
2454 Isolate* isolate = thread->isolate(); 2432 Isolate* isolate = thread->isolate();
2455 Class& cls = Class::Handle(zone); 2433 Class& cls = Class::Handle(zone);
2456 AbstractType& sup_type = AbstractType::Handle(zone); 2434 AbstractType& sup_type = AbstractType::Handle(zone);
2457 cls = raw(); 2435 cls = raw();
2458 intptr_t num_type_args = 0; 2436 intptr_t num_type_args = 0;
2459 do { 2437 do {
2460 if (cls.IsSignatureClass()) {
2461 Function& signature_fun = Function::Handle(zone);
2462 signature_fun ^= cls.signature_function();
2463 if (!signature_fun.is_static() &&
2464 !signature_fun.HasInstantiatedSignature()) {
2465 cls = signature_fun.Owner();
2466 }
2467 }
2468 // Calling NumOwnTypeArguments() on a mixin application class will setup the 2438 // Calling NumOwnTypeArguments() on a mixin application class will setup the
2469 // type parameters if not already done. 2439 // type parameters if not already done.
2470 num_type_args += cls.NumOwnTypeArguments(); 2440 num_type_args += cls.NumOwnTypeArguments();
2471 // Super type of Object class is null. 2441 // Super type of Object class is null.
2472 if ((cls.super_type() == AbstractType::null()) || 2442 if ((cls.super_type() == AbstractType::null()) ||
2473 (cls.super_type() == isolate->object_store()->object_type())) { 2443 (cls.super_type() == isolate->object_store()->object_type())) {
2474 break; 2444 break;
2475 } 2445 }
2476 sup_type = cls.super_type(); 2446 sup_type = cls.super_type();
2477 ClassFinalizer::ResolveTypeClass(cls, sup_type); 2447 // A BoundedType, TypeRef, or FunctionType can appear as type argument of
2448 // sup_type, but not as sup_type itself.
2449 ASSERT(sup_type.IsType());
2450 sup_type = ClassFinalizer::ResolveTypeClass(cls, Type::Cast(sup_type));
2478 cls = sup_type.type_class(); 2451 cls = sup_type.type_class();
2452 ASSERT(!cls.IsTypedefClass());
2479 } while (true); 2453 } while (true);
2480 set_num_type_arguments(num_type_args); 2454 set_num_type_arguments(num_type_args);
2481 return num_type_args; 2455 return num_type_args;
2482 } 2456 }
2483 2457
2484 2458
2485 RawClass* Class::SuperClass() const { 2459 RawClass* Class::SuperClass() const {
2486 if (super_type() == AbstractType::null()) { 2460 if (super_type() == AbstractType::null()) {
2487 return Class::null(); 2461 return Class::null();
2488 } 2462 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2520 if (type_param_name.Equals(type_name)) { 2494 if (type_param_name.Equals(type_name)) {
2521 return type_param.raw(); 2495 return type_param.raw();
2522 } 2496 }
2523 } 2497 }
2524 } 2498 }
2525 return TypeParameter::null(); 2499 return TypeParameter::null();
2526 } 2500 }
2527 2501
2528 2502
2529 void Class::CalculateFieldOffsets() const { 2503 void Class::CalculateFieldOffsets() const {
2504 ASSERT(id() != kClosureCid); // Class _Closure is prefinalized.
2530 Array& flds = Array::Handle(fields()); 2505 Array& flds = Array::Handle(fields());
2531 const Class& super = Class::Handle(SuperClass()); 2506 const Class& super = Class::Handle(SuperClass());
2532 intptr_t offset = 0; 2507 intptr_t offset = 0;
2533 intptr_t type_args_field_offset = kNoTypeArguments; 2508 intptr_t type_args_field_offset = kNoTypeArguments;
2534 if (super.IsNull()) { 2509 if (super.IsNull()) {
2535 offset = Instance::NextFieldOffset(); 2510 offset = Instance::NextFieldOffset();
2536 ASSERT(offset > 0); 2511 ASSERT(offset > 0);
2537 } else { 2512 } else {
2538 ASSERT(super.is_finalized() || super.is_prefinalized()); 2513 ASSERT(super.is_finalized() || super.is_prefinalized());
2539 type_args_field_offset = super.type_arguments_field_offset(); 2514 type_args_field_offset = super.type_arguments_field_offset();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2733 } 2708 }
2734 2709
2735 2710
2736 void Class::set_invocation_dispatcher_cache(const Array& cache) const { 2711 void Class::set_invocation_dispatcher_cache(const Array& cache) const {
2737 StorePointer(&raw_ptr()->invocation_dispatcher_cache_, cache.raw()); 2712 StorePointer(&raw_ptr()->invocation_dispatcher_cache_, cache.raw());
2738 } 2713 }
2739 2714
2740 2715
2741 void Class::Finalize() const { 2716 void Class::Finalize() const {
2742 ASSERT(Thread::Current()->IsMutatorThread()); 2717 ASSERT(Thread::Current()->IsMutatorThread());
2743 // Even if all regular classes are prefinalized (precompilation), signature 2718 ASSERT(!Isolate::Current()->all_classes_finalized());
2744 // classes may be added later when we encounter local functions.
2745 ASSERT(IsSignatureClass() || !Isolate::Current()->all_classes_finalized());
2746 ASSERT(!is_finalized()); 2719 ASSERT(!is_finalized());
2747 // Prefinalized classes have a VM internal representation and no Dart fields. 2720 // Prefinalized classes have a VM internal representation and no Dart fields.
2748 // Their instance size is precomputed and field offsets are known. 2721 // Their instance size is precomputed and field offsets are known.
2749 if (!is_prefinalized()) { 2722 if (!is_prefinalized()) {
2750 // Compute offsets of instance fields and instance size. 2723 // Compute offsets of instance fields and instance size.
2751 CalculateFieldOffsets(); 2724 CalculateFieldOffsets();
2752 } 2725 }
2753 set_is_finalized(); 2726 set_is_finalized();
2754 } 2727 }
2755 2728
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
3118 const Script& script, 3091 const Script& script,
3119 intptr_t token_pos) { 3092 intptr_t token_pos) {
3120 Class& result = Class::Handle(New<Instance>(kIllegalCid)); 3093 Class& result = Class::Handle(New<Instance>(kIllegalCid));
3121 result.set_name(name); 3094 result.set_name(name);
3122 result.set_script(script); 3095 result.set_script(script);
3123 result.set_token_pos(token_pos); 3096 result.set_token_pos(token_pos);
3124 return result.raw(); 3097 return result.raw();
3125 } 3098 }
3126 3099
3127 3100
3128 RawClass* Class::NewSignatureClass(const String& name,
3129 const Function& signature_function,
3130 const Script& script,
3131 intptr_t token_pos) {
3132 const Class& result = Class::Handle(New(name, script, token_pos));
3133 // Instances of a signature class can only be closures.
3134 result.set_instance_size(Closure::InstanceSize());
3135 result.set_next_field_offset(Closure::NextFieldOffset());
3136 // Signature classes extend the _FunctionImpl class.
3137 result.set_super_type(Type::Handle(
3138 Isolate::Current()->object_store()->function_impl_type()));
3139 result.set_is_synthesized_class();
3140 result.set_type_arguments_field_offset(Closure::type_arguments_offset());
3141 if (!signature_function.IsNull()) {
3142 result.PatchSignatureFunction(signature_function);
3143 }
3144 return result.raw();
3145 }
3146
3147
3148 void Class::PatchSignatureFunction(const Function& signature_function) const {
3149 ASSERT(!signature_function.IsNull());
3150 set_signature_function(signature_function);
3151 const Class& owner_class = Class::Handle(signature_function.Owner());
3152 ASSERT(!owner_class.IsNull());
3153 // A signature class extends class Instance and is either not parameterized or
3154 // parameterized with exactly the same list of type parameters as the owner
3155 // class of its function.
3156 // In case of a function type alias, the function owner is the alias class,
3157 // which is also the signature class. The signature class is therefore
3158 // parameterized according to the alias class declaration, even if the
3159 // function type is not generic.
3160 // Otherwise, if the function is static or if its signature type is
3161 // non-generic, i.e. it does not depend on any type parameter of the owner
3162 // class, then the signature class is not parameterized, although the owner
3163 // class may be.
3164 if (owner_class.raw() == raw()) {
3165 // This signature class is an alias, which cannot be the canonical
3166 // signature class for this signature function.
3167 ASSERT(!IsCanonicalSignatureClass());
3168 // Do not modify the declared type parameters of the alias, even if unused.
3169 } else {
3170 // Copy the type parameters only for an instance function type that is not
3171 // instantiated, i.e. that depends on the type parameters of the owner
3172 // class.
3173 // TODO(regis): Verify that it is not a problem for the copied type
3174 // parameters to refer to the owner class rather than to the signature
3175 // class. In other words, uninstantiated function types should only get
3176 // instantiated by the owner class as instantiator and never by the
3177 // signature class itself.
3178 TypeArguments& type_parameters = TypeArguments::Handle();
3179 if (!signature_function.is_static() &&
3180 (owner_class.NumTypeParameters() > 0) &&
3181 !signature_function.HasInstantiatedSignature()) {
3182 type_parameters = owner_class.type_parameters();
3183 }
3184 set_type_parameters(type_parameters);
3185 if (signature_function.signature_class() == Object::null()) {
3186 // Make this signature class the canonical signature class.
3187 signature_function.set_signature_class(*this);
3188 ASSERT(IsCanonicalSignatureClass());
3189 }
3190 }
3191 set_is_prefinalized();
3192 }
3193
3194
3195 RawClass* Class::NewNativeWrapper(const Library& library, 3101 RawClass* Class::NewNativeWrapper(const Library& library,
3196 const String& name, 3102 const String& name,
3197 int field_count) { 3103 int field_count) {
3198 Class& cls = Class::Handle(library.LookupClass(name)); 3104 Class& cls = Class::Handle(library.LookupClass(name));
3199 if (cls.IsNull()) { 3105 if (cls.IsNull()) {
3200 cls = New(name, Script::Handle(), Scanner::kNoSourcePos); 3106 cls = New(name, Script::Handle(), Scanner::kNoSourcePos);
3201 cls.SetFields(Object::empty_array()); 3107 cls.SetFields(Object::empty_array());
3202 cls.SetFunctions(Object::empty_array()); 3108 cls.SetFunctions(Object::empty_array());
3203 // Set super class to Object. 3109 // Set super class to Object.
3204 cls.set_super_type(Type::Handle(Type::ObjectType())); 3110 cls.set_super_type(Type::Handle(Type::ObjectType()));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3282 } 3188 }
3283 } 3189 }
3284 3190
3285 3191
3286 void Class::set_user_name(const String& value) const { 3192 void Class::set_user_name(const String& value) const {
3287 StorePointer(&raw_ptr()->user_name_, value.raw()); 3193 StorePointer(&raw_ptr()->user_name_, value.raw());
3288 } 3194 }
3289 3195
3290 3196
3291 RawString* Class::GeneratePrettyName() const { 3197 RawString* Class::GeneratePrettyName() const {
3292 if (!IsCanonicalSignatureClass()) { 3198 const String& name = String::Handle(Name());
3293 const String& name = String::Handle(Name()); 3199 return String::IdentifierPrettyName(name);
3294 return String::IdentifierPrettyName(name);
3295 } else {
3296 return Name();
3297 }
3298 } 3200 }
3299 3201
3300 3202
3301 RawString* Class::GenerateUserVisibleName() const { 3203 RawString* Class::GenerateUserVisibleName() const {
3302 if (FLAG_show_internal_names) { 3204 if (FLAG_show_internal_names) {
3303 return Name(); 3205 return Name();
3304 } 3206 }
3305 switch (id()) { 3207 switch (id()) {
3306 case kNullCid: 3208 case kNullCid:
3307 return Symbols::Null().raw(); 3209 return Symbols::Null().raw();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
3425 case kTypedDataFloat64x2ArrayCid: 3327 case kTypedDataFloat64x2ArrayCid:
3426 case kExternalTypedDataFloat64x2ArrayCid: 3328 case kExternalTypedDataFloat64x2ArrayCid:
3427 return Symbols::Float64x2List().raw(); 3329 return Symbols::Float64x2List().raw();
3428 case kTypedDataFloat32ArrayCid: 3330 case kTypedDataFloat32ArrayCid:
3429 case kExternalTypedDataFloat32ArrayCid: 3331 case kExternalTypedDataFloat32ArrayCid:
3430 return Symbols::Float32List().raw(); 3332 return Symbols::Float32List().raw();
3431 case kTypedDataFloat64ArrayCid: 3333 case kTypedDataFloat64ArrayCid:
3432 case kExternalTypedDataFloat64ArrayCid: 3334 case kExternalTypedDataFloat64ArrayCid:
3433 return Symbols::Float64List().raw(); 3335 return Symbols::Float64List().raw();
3434 default: 3336 default:
3435 if (!IsCanonicalSignatureClass()) { 3337 const String& name = String::Handle(Name());
3436 const String& name = String::Handle(Name()); 3338 return String::IdentifierPrettyName(name);
3437 return String::IdentifierPrettyName(name);
3438 } else {
3439 return Name();
3440 }
3441 } 3339 }
3442 UNREACHABLE(); 3340 UNREACHABLE();
3443 } 3341 }
3444 3342
3445 3343
3446 void Class::set_script(const Script& value) const { 3344 void Class::set_script(const Script& value) const {
3447 StorePointer(&raw_ptr()->script_, value.raw()); 3345 StorePointer(&raw_ptr()->script_, value.raw());
3448 } 3346 }
3449 3347
3450 3348
3451 void Class::set_token_pos(intptr_t token_pos) const { 3349 void Class::set_token_pos(intptr_t token_pos) const {
3452 ASSERT(Scanner::ValidSourcePosition(token_pos)); 3350 ASSERT(Scanner::ValidSourcePosition(token_pos));
3453 StoreNonPointer(&raw_ptr()->token_pos_, token_pos); 3351 StoreNonPointer(&raw_ptr()->token_pos_, token_pos);
3454 } 3352 }
3455 3353
3456 3354
3457 intptr_t Class::ComputeEndTokenPos() const { 3355 intptr_t Class::ComputeEndTokenPos() const {
3458 // Return the begin token for synthetic classes. 3356 // Return the begin token for synthetic classes.
3459 if (IsSignatureClass() || IsMixinApplication() || IsTopLevel()) { 3357 if (IsMixinApplication() || IsTopLevel()) {
3460 return token_pos(); 3358 return token_pos();
3461 } 3359 }
3462 const Script& scr = Script::Handle(script()); 3360 const Script& scr = Script::Handle(script());
3463 ASSERT(!scr.IsNull()); 3361 ASSERT(!scr.IsNull());
3464 const TokenStream& tkns = TokenStream::Handle(scr.tokens()); 3362 const TokenStream& tkns = TokenStream::Handle(scr.tokens());
3465 TokenStream::Iterator tkit( 3363 TokenStream::Iterator tkit(
3466 tkns, token_pos(), TokenStream::Iterator::kNoNewlines); 3364 tkns, token_pos(), TokenStream::Iterator::kNoNewlines);
3467 intptr_t level = 0; 3365 intptr_t level = 0;
3468 while (tkit.CurrentTokenKind() != Token::kEOS) { 3366 while (tkit.CurrentTokenKind() != Token::kEOS) {
3469 if (tkit.CurrentTokenKind() == Token::kLBRACE) { 3367 if (tkit.CurrentTokenKind() == Token::kLBRACE) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
3632 } 3530 }
3633 3531
3634 3532
3635 void Class::set_canonical_types(const Object& value) const { 3533 void Class::set_canonical_types(const Object& value) const {
3636 ASSERT(!value.IsNull()); 3534 ASSERT(!value.IsNull());
3637 StorePointer(&raw_ptr()->canonical_types_, value.raw()); 3535 StorePointer(&raw_ptr()->canonical_types_, value.raw());
3638 } 3536 }
3639 3537
3640 3538
3641 RawType* Class::CanonicalType() const { 3539 RawType* Class::CanonicalType() const {
3642 if (!IsGeneric()) { 3540 if (!IsGeneric() && !IsClosureClass()) {
3643 return reinterpret_cast<RawType*>(raw_ptr()->canonical_types_); 3541 return reinterpret_cast<RawType*>(raw_ptr()->canonical_types_);
3644 } 3542 }
3645 Array& types = Array::Handle(); 3543 Array& types = Array::Handle();
3646 types ^= canonical_types(); 3544 types ^= canonical_types();
3647 if (!types.IsNull() && (types.Length() > 0)) { 3545 if (!types.IsNull() && (types.Length() > 0)) {
3648 return reinterpret_cast<RawType*>(types.At(0)); 3546 return reinterpret_cast<RawType*>(types.At(0));
3649 } 3547 }
3650 return reinterpret_cast<RawType*>(Object::null()); 3548 return reinterpret_cast<RawType*>(Object::null());
3651 } 3549 }
3652 3550
3653 3551
3654 void Class::SetCanonicalType(const Type& type) const { 3552 void Class::SetCanonicalType(const Type& type) const {
3655 ASSERT(type.IsCanonical()); 3553 ASSERT(type.IsCanonical());
3656 if (!IsGeneric()) { 3554 if (!IsGeneric() && !IsClosureClass()) {
3657 ASSERT((canonical_types() == Object::null()) || 3555 ASSERT((canonical_types() == Object::null()) ||
3658 (canonical_types() == type.raw())); // Set during own finalization. 3556 (canonical_types() == type.raw())); // Set during own finalization.
3659 set_canonical_types(type); 3557 set_canonical_types(type);
3660 } else { 3558 } else {
3661 Array& types = Array::Handle(); 3559 Array& types = Array::Handle();
3662 types ^= canonical_types(); 3560 types ^= canonical_types();
3663 ASSERT(!types.IsNull() && (types.Length() > 1)); 3561 ASSERT(!types.IsNull() && (types.Length() > 1));
3664 ASSERT((types.At(0) == Object::null()) || (types.At(0) == type.raw())); 3562 ASSERT((types.At(0) == Object::null()) || (types.At(0) == type.raw()));
3665 types.SetAt(0, type); 3563 types.SetAt(0, type);
3666 } 3564 }
3667 } 3565 }
3668 3566
3669 3567
3670 intptr_t Class::FindCanonicalTypeIndex(const Type& needle) const { 3568 intptr_t Class::FindCanonicalTypeIndex(const AbstractType& needle) const {
3671 Thread* thread = Thread::Current(); 3569 Thread* thread = Thread::Current();
3672 if (EnsureIsFinalized(thread) != Error::null()) { 3570 if (EnsureIsFinalized(thread) != Error::null()) {
3673 return -1; 3571 return -1;
3674 } 3572 }
3675 if (needle.raw() == CanonicalType()) { 3573 if (needle.raw() == CanonicalType()) {
3676 // For a generic type or signature type, there exists another index with the 3574 // For a generic type or signature type, there exists another index with the
3677 // same type. It will never be returned by this function. 3575 // same type. It will never be returned by this function.
3678 return 0; 3576 return 0;
3679 } 3577 }
3680 REUSABLE_OBJECT_HANDLESCOPE(thread); 3578 REUSABLE_OBJECT_HANDLESCOPE(thread);
3681 Object& types = thread->ObjectHandle(); 3579 Object& types = thread->ObjectHandle();
3682 types = canonical_types(); 3580 types = canonical_types();
3683 if (types.IsNull()) { 3581 if (types.IsNull()) {
3684 return -1; 3582 return -1;
3685 } 3583 }
3686 const intptr_t len = Array::Cast(types).Length(); 3584 const intptr_t len = Array::Cast(types).Length();
3687 REUSABLE_ABSTRACT_TYPE_HANDLESCOPE(thread); 3585 REUSABLE_ABSTRACT_TYPE_HANDLESCOPE(thread);
3688 AbstractType& type = thread->AbstractTypeHandle(); 3586 AbstractType& type = thread->AbstractTypeHandle();
3689 for (intptr_t i = 0; i < len; i++) { 3587 for (intptr_t i = 0; i < len; i++) {
3690 type ^= Array::Cast(types).At(i); 3588 type ^= Array::Cast(types).At(i);
3691 if (needle.raw() == type.raw()) { 3589 if (needle.raw() == type.raw()) {
3692 return i; 3590 return i;
3693 } 3591 }
3694 } 3592 }
3695 // No type found. 3593 // No type found.
3696 return -1; 3594 return -1;
3697 } 3595 }
3698 3596
3699 3597
3700 RawType* Class::CanonicalTypeFromIndex(intptr_t idx) const { 3598 RawAbstractType* Class::CanonicalTypeFromIndex(intptr_t idx) const {
3701 Type& type = Type::Handle(); 3599 AbstractType& type = AbstractType::Handle();
3702 if (idx == 0) { 3600 if (idx == 0) {
3703 type = CanonicalType(); 3601 type = CanonicalType();
3704 if (!type.IsNull()) { 3602 if (!type.IsNull()) {
3705 return type.raw(); 3603 return type.raw();
3706 } 3604 }
3707 } 3605 }
3708 Object& types = Object::Handle(canonical_types()); 3606 Object& types = Object::Handle(canonical_types());
3709 if (types.IsNull() || !types.IsArray()) { 3607 if (types.IsNull() || !types.IsArray()) {
3710 return Type::null(); 3608 return Type::null();
3711 } 3609 }
(...skipping 26 matching lines...) Expand all
3738 // Disassociate the existing stub from class. 3636 // Disassociate the existing stub from class.
3739 StorePointer(&raw_ptr()->allocation_stub_, Code::null()); 3637 StorePointer(&raw_ptr()->allocation_stub_, Code::null());
3740 } 3638 }
3741 3639
3742 3640
3743 bool Class::IsFunctionClass() const { 3641 bool Class::IsFunctionClass() const {
3744 return raw() == Type::Handle(Type::Function()).type_class(); 3642 return raw() == Type::Handle(Type::Function()).type_class();
3745 } 3643 }
3746 3644
3747 3645
3748 bool Class::IsCanonicalSignatureClass() const {
3749 const Function& function = Function::Handle(signature_function());
3750 return (!function.IsNull() && (function.signature_class() == raw()));
3751 }
3752
3753
3754 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T. 3646 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T.
3755 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T. 3647 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T.
3756 // Type S is specified by this class parameterized with 'type_arguments', and 3648 // Type S is specified by this class parameterized with 'type_arguments', and
3757 // type T by class 'other' parameterized with 'other_type_arguments'. 3649 // type T by class 'other' parameterized with 'other_type_arguments'.
3758 // This class and class 'other' do not need to be finalized, however, they must 3650 // This class and class 'other' do not need to be finalized, however, they must
3759 // be resolved as well as their interfaces. 3651 // be resolved as well as their interfaces.
3760 bool Class::TypeTestNonRecursive(const Class& cls, 3652 bool Class::TypeTestNonRecursive(const Class& cls,
3761 Class::TypeTestKind test_kind, 3653 Class::TypeTestKind test_kind,
3762 const TypeArguments& type_arguments, 3654 const TypeArguments& type_arguments,
3763 const Class& other, 3655 const Class& other,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3816 // above. 3708 // above.
3817 return test_kind == Class::kIsSubtypeOf; 3709 return test_kind == Class::kIsSubtypeOf;
3818 } 3710 }
3819 return type_arguments.TypeTest(test_kind, 3711 return type_arguments.TypeTest(test_kind,
3820 other_type_arguments, 3712 other_type_arguments,
3821 from_index, 3713 from_index,
3822 num_type_params, 3714 num_type_params,
3823 bound_error, 3715 bound_error,
3824 space); 3716 space);
3825 } 3717 }
3826 const bool other_is_function_class = other.IsFunctionClass(); 3718 if (other.IsFunctionClass()) {
3827 if (other.IsSignatureClass() || other_is_function_class) { 3719 // Check if type S has a call() method.
3828 const Function& other_fun = Function::Handle(zone,
3829 other.signature_function());
3830 if (thsi.IsSignatureClass()) {
3831 if (other_is_function_class) {
3832 return true;
3833 }
3834 // Check for two function types.
3835 const Function& fun =
3836 Function::Handle(zone, thsi.signature_function());
3837 return fun.TypeTest(test_kind,
3838 type_arguments,
3839 other_fun,
3840 other_type_arguments,
3841 bound_error,
3842 space);
3843 }
3844 // Check if type S has a call() method of function type T.
3845 Function& function = 3720 Function& function =
3846 Function::Handle(zone, thsi.LookupDynamicFunction(Symbols::Call())); 3721 Function::Handle(zone, thsi.LookupDynamicFunction(Symbols::Call()));
3847 if (function.IsNull()) { 3722 if (function.IsNull()) {
3848 // Walk up the super_class chain. 3723 // Walk up the super_class chain.
3849 Class& cls = Class::Handle(zone, thsi.SuperClass()); 3724 Class& cls = Class::Handle(zone, thsi.SuperClass());
3850 while (!cls.IsNull() && function.IsNull()) { 3725 while (!cls.IsNull() && function.IsNull()) {
3851 function = cls.LookupDynamicFunction(Symbols::Call()); 3726 function = cls.LookupDynamicFunction(Symbols::Call());
3852 cls = cls.SuperClass(); 3727 cls = cls.SuperClass();
3853 } 3728 }
3854 } 3729 }
3855 if (!function.IsNull()) { 3730 if (!function.IsNull()) {
3856 if (other_is_function_class || 3731 return true;
3857 function.TypeTest(test_kind,
3858 type_arguments,
3859 other_fun,
3860 other_type_arguments,
3861 bound_error,
3862 space)) {
3863 return true;
3864 }
3865 } 3732 }
3866 } 3733 }
3867 // Check for 'direct super type' specified in the implements clause 3734 // Check for 'direct super type' specified in the implements clause
3868 // and check for transitivity at the same time. 3735 // and check for transitivity at the same time.
3869 Array& interfaces = Array::Handle(zone, thsi.interfaces()); 3736 Array& interfaces = Array::Handle(zone, thsi.interfaces());
3870 AbstractType& interface = AbstractType::Handle(zone); 3737 AbstractType& interface = AbstractType::Handle(zone);
3871 Class& interface_class = Class::Handle(zone); 3738 Class& interface_class = Class::Handle(zone);
3872 TypeArguments& interface_args = TypeArguments::Handle(zone); 3739 TypeArguments& interface_args = TypeArguments::Handle(zone);
3873 Error& error = Error::Handle(zone); 3740 Error& error = Error::Handle(zone);
3874 for (intptr_t i = 0; i < interfaces.Length(); i++) { 3741 for (intptr_t i = 0; i < interfaces.Length(); i++) {
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after
4894 if (prior_instantiations.At(index) == instantiator_type_arguments.raw()) { 4761 if (prior_instantiations.At(index) == instantiator_type_arguments.raw()) {
4895 return TypeArguments::RawCast(prior_instantiations.At(index + 1)); 4762 return TypeArguments::RawCast(prior_instantiations.At(index + 1));
4896 } 4763 }
4897 if (prior_instantiations.At(index) == Smi::New(StubCode::kNoInstantiator)) { 4764 if (prior_instantiations.At(index) == Smi::New(StubCode::kNoInstantiator)) {
4898 break; 4765 break;
4899 } 4766 }
4900 index += 2; 4767 index += 2;
4901 } 4768 }
4902 // Cache lookup failed. Instantiate the type arguments. 4769 // Cache lookup failed. Instantiate the type arguments.
4903 TypeArguments& result = TypeArguments::Handle(); 4770 TypeArguments& result = TypeArguments::Handle();
4904 result = InstantiateFrom(instantiator_type_arguments, bound_error); 4771 result = InstantiateFrom(
4772 instantiator_type_arguments, bound_error, NULL, Heap::kOld);
4905 if ((bound_error != NULL) && !bound_error->IsNull()) { 4773 if ((bound_error != NULL) && !bound_error->IsNull()) {
4906 return result.raw(); 4774 return result.raw();
4907 } 4775 }
4908 // Instantiation did not result in bound error. Canonicalize type arguments. 4776 // Instantiation did not result in bound error. Canonicalize type arguments.
4909 result = result.Canonicalize(); 4777 result = result.Canonicalize();
4910 // InstantiateAndCanonicalizeFrom is not reentrant. It cannot have been called 4778 // InstantiateAndCanonicalizeFrom is not reentrant. It cannot have been called
4911 // indirectly, so the prior_instantiations array cannot have grown. 4779 // indirectly, so the prior_instantiations array cannot have grown.
4912 ASSERT(prior_instantiations.raw() == instantiations()); 4780 ASSERT(prior_instantiations.raw() == instantiations());
4913 // Add instantiator and result to instantiations array. 4781 // Add instantiator and result to instantiations array.
4914 intptr_t length = prior_instantiations.Length(); 4782 intptr_t length = prior_instantiations.Length();
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
5486 ASSERT(obj.IsArray()); 5354 ASSERT(obj.IsArray());
5487 ASSERT((Array::Cast(obj).At(1) == Object::null()) || value.IsNull()); 5355 ASSERT((Array::Cast(obj).At(1) == Object::null()) || value.IsNull());
5488 Array::Cast(obj).SetAt(1, value); 5356 Array::Cast(obj).SetAt(1, value);
5489 } else { 5357 } else {
5490 ASSERT((raw_ptr()->data_ == Object::null()) || value.IsNull()); 5358 ASSERT((raw_ptr()->data_ == Object::null()) || value.IsNull());
5491 set_data(value); 5359 set_data(value);
5492 } 5360 }
5493 } 5361 }
5494 5362
5495 5363
5496 RawClass* Function::signature_class() const { 5364 RawFunctionType* Function::SignatureType() const {
5365 FunctionType& type = FunctionType::Handle();
5366 const Object& obj = Object::Handle(raw_ptr()->data_);
5497 if (IsSignatureFunction()) { 5367 if (IsSignatureFunction()) {
5498 const Object& obj = Object::Handle(raw_ptr()->data_); 5368 ASSERT(obj.IsNull() || obj.IsFunctionType());
5499 ASSERT(obj.IsNull() || obj.IsClass()); 5369 type = obj.IsNull() ? FunctionType::null() : FunctionType::Cast(obj).raw();
5500 return (obj.IsNull()) ? Class::null() : Class::Cast(obj).raw(); 5370 } else {
5371 ASSERT(IsClosureFunction());
5372 ASSERT(!obj.IsNull());
5373 type = ClosureData::Cast(obj).signature_type();
5501 } 5374 }
5502 if (IsClosureFunction()) { 5375 if (type.IsNull()) {
5503 const Object& obj = Object::Handle(raw_ptr()->data_); 5376 // A function type is parameterized in the same way as the owner class of
5504 ASSERT(!obj.IsNull()); 5377 // its non-static signature function.
5505 return ClosureData::Cast(obj).signature_class(); 5378 // It is not type parameterized if its signature function is static.
5379 // During type finalization, the type arguments of the super class of the
5380 // owner class of its signature function will be prepended to the type
5381 // argument vector. Therefore, we only need to set the type arguments
5382 // matching the type parameters here.
5383 // In case of a function type alias, the function owner is the alias class,
5384 // i.e. the typedef. The signature type is therefore parameterized according
5385 // to the alias class declaration, even if the function type is not generic.
5386 // Otherwise, if the function is static or if its signature type is
5387 // non-generic, i.e. it does not depend on any type parameter of the owner
5388 // class, then the signature type is not parameterized, although the owner
5389 // class may be. In this case, the scope class of the function type is reset
5390 // to _Closure class as well as the owner of the signature function.
5391 Class& scope_class = Class::Handle(Owner());
5392 if (!scope_class.IsTypedefClass() &&
5393 (is_static() ||
5394 !scope_class.IsGeneric() ||
5395 HasInstantiatedSignature())) {
5396 scope_class = Isolate::Current()->object_store()->closure_class();
5397 if (IsSignatureFunction()) {
5398 set_owner(scope_class);
5399 set_token_pos(Scanner::kNoSourcePos);
5400 }
5401 }
5402 const TypeArguments& signature_type_arguments =
5403 TypeArguments::Handle(scope_class.type_parameters());
5404 // Return the still unfinalized signature type.
5405 type = FunctionType::New(scope_class,
5406 signature_type_arguments,
5407 *this,
5408 token_pos());
5409
5410 SetSignatureType(type);
5506 } 5411 }
5507 return Class::null(); 5412 return type.raw();
5508 } 5413 }
5509 5414
5510 5415
5511 void Function::set_signature_class(const Class& value) const { 5416 void Function::SetSignatureType(const FunctionType& value) const {
5512 if (IsSignatureFunction()) { 5417 if (IsSignatureFunction()) {
5513 set_data(value); 5418 set_data(value);
5514 return; 5419 } else {
5515 } 5420 ASSERT(IsClosureFunction());
5516 if (IsClosureFunction()) {
5517 const Object& obj = Object::Handle(raw_ptr()->data_); 5421 const Object& obj = Object::Handle(raw_ptr()->data_);
5518 ASSERT(!obj.IsNull()); 5422 ASSERT(!obj.IsNull());
5519 ClosureData::Cast(obj).set_signature_class(value); 5423 ClosureData::Cast(obj).set_signature_type(value);
5520 return;
5521 } 5424 }
5522 UNREACHABLE();
5523 } 5425 }
5524 5426
5525 5427
5526 bool Function::IsRedirectingFactory() const { 5428 bool Function::IsRedirectingFactory() const {
5527 if (!IsFactory() || !is_redirecting()) { 5429 if (!IsFactory() || !is_redirecting()) {
5528 return false; 5430 return false;
5529 } 5431 }
5530 ASSERT(!IsClosureFunction()); // A factory cannot also be a closure. 5432 ASSERT(!IsClosureFunction()); // A factory cannot also be a closure.
5531 return true; 5433 return true;
5532 } 5434 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
5633 if (obj.IsNull()) { 5535 if (obj.IsNull()) {
5634 obj = RedirectionData::New(); 5536 obj = RedirectionData::New();
5635 set_data(obj); 5537 set_data(obj);
5636 } 5538 }
5637 RedirectionData::Cast(obj).set_target(target); 5539 RedirectionData::Cast(obj).set_target(target);
5638 } 5540 }
5639 5541
5640 5542
5641 // This field is heavily overloaded: 5543 // This field is heavily overloaded:
5642 // eval function: Script expression source 5544 // eval function: Script expression source
5643 // signature function: Class signature class 5545 // signature function: Function type
5644 // method extractor: Function extracted closure function 5546 // method extractor: Function extracted closure function
5645 // noSuchMethod dispatcher: Array arguments descriptor 5547 // noSuchMethod dispatcher: Array arguments descriptor
5646 // invoke-field dispatcher: Array arguments descriptor 5548 // invoke-field dispatcher: Array arguments descriptor
5647 // redirecting constructor: RedirectionData 5549 // redirecting constructor: RedirectionData
5648 // closure function: ClosureData 5550 // closure function: ClosureData
5649 // irregexp function: Array[0] = JSRegExp 5551 // irregexp function: Array[0] = JSRegExp
5650 // Array[1] = Smi string specialization cid 5552 // Array[1] = Smi string specialization cid
5651 // native function: Array[0] = String native name 5553 // native function: Array[0] = String native name
5652 // Array[1] = Function implicit closure function 5554 // Array[1] = Function implicit closure function
5653 // regular function: Function for implicit closure function 5555 // regular function: Function for implicit closure function
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
5780 5682
5781 5683
5782 void Function::set_recognized_kind(MethodRecognizer::Kind value) const { 5684 void Function::set_recognized_kind(MethodRecognizer::Kind value) const {
5783 // Prevent multiple settings of kind. 5685 // Prevent multiple settings of kind.
5784 ASSERT((value == MethodRecognizer::kUnknown) || !IsRecognized()); 5686 ASSERT((value == MethodRecognizer::kUnknown) || !IsRecognized());
5785 set_kind_tag(RecognizedBits::update(value, raw_ptr()->kind_tag_)); 5687 set_kind_tag(RecognizedBits::update(value, raw_ptr()->kind_tag_));
5786 } 5688 }
5787 5689
5788 5690
5789 void Function::set_token_pos(intptr_t token_pos) const { 5691 void Function::set_token_pos(intptr_t token_pos) const {
5790 ASSERT(token_pos >= 0); 5692 ASSERT(Scanner::ValidSourcePosition(token_pos));
5791 StoreNonPointer(&raw_ptr()->token_pos_, token_pos); 5693 StoreNonPointer(&raw_ptr()->token_pos_, token_pos);
5792 } 5694 }
5793 5695
5794 5696
5795 void Function::set_kind_tag(intptr_t value) const { 5697 void Function::set_kind_tag(intptr_t value) const {
5796 StoreNonPointer(&raw_ptr()->kind_tag_, static_cast<uint32_t>(value)); 5698 StoreNonPointer(&raw_ptr()->kind_tag_, static_cast<uint32_t>(value));
5797 } 5699 }
5798 5700
5799 5701
5800 void Function::set_num_fixed_parameters(intptr_t value) const { 5702 void Function::set_num_fixed_parameters(intptr_t value) const {
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
6498 /* is_abstract = */ false, 6400 /* is_abstract = */ false,
6499 /* is_external = */ false, 6401 /* is_external = */ false,
6500 parent.is_native(), 6402 parent.is_native(),
6501 parent_owner, 6403 parent_owner,
6502 token_pos)); 6404 token_pos));
6503 result.set_parent_function(parent); 6405 result.set_parent_function(parent);
6504 return result.raw(); 6406 return result.raw();
6505 } 6407 }
6506 6408
6507 6409
6410 RawFunction* Function::NewSignatureFunction(const Class& owner,
6411 intptr_t token_pos) {
6412 const Function& result = Function::Handle(Function::New(
6413 Symbols::AnonymousSignature(),
6414 RawFunction::kSignatureFunction,
6415 /* is_static = */ false,
6416 /* is_const = */ false,
6417 /* is_abstract = */ false,
6418 /* is_external = */ false,
6419 /* is_native = */ false,
6420 owner, // Same as function type scope class.
6421 token_pos));
6422 result.set_is_reflectable(false);
6423 result.set_is_visible(false);
6424 result.set_is_debuggable(false);
6425 return result.raw();
6426 }
6427
6428
6508 RawFunction* Function::NewEvalFunction(const Class& owner, 6429 RawFunction* Function::NewEvalFunction(const Class& owner,
6509 const Script& script, 6430 const Script& script,
6510 bool is_static) { 6431 bool is_static) {
6511 const Function& result = Function::Handle( 6432 const Function& result = Function::Handle(
6512 Function::New(String::Handle(Symbols::New(":Eval")), 6433 Function::New(String::Handle(Symbols::New(":Eval")),
6513 RawFunction::kRegularFunction, 6434 RawFunction::kRegularFunction,
6514 is_static, 6435 is_static,
6515 /* is_const = */ false, 6436 /* is_const = */ false,
6516 /* is_abstract = */ false, 6437 /* is_abstract = */ false,
6517 /* is_external = */ false, 6438 /* is_external = */ false,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
6576 // Add implicit closure object parameter. 6497 // Add implicit closure object parameter.
6577 param_type = Type::DynamicType(); 6498 param_type = Type::DynamicType();
6578 closure_function.SetParameterTypeAt(0, param_type); 6499 closure_function.SetParameterTypeAt(0, param_type);
6579 closure_function.SetParameterNameAt(0, Symbols::ClosureParameter()); 6500 closure_function.SetParameterNameAt(0, Symbols::ClosureParameter());
6580 for (int i = kClosure; i < num_params; i++) { 6501 for (int i = kClosure; i < num_params; i++) {
6581 param_type = ParameterTypeAt(has_receiver - kClosure + i); 6502 param_type = ParameterTypeAt(has_receiver - kClosure + i);
6582 closure_function.SetParameterTypeAt(i, param_type); 6503 closure_function.SetParameterTypeAt(i, param_type);
6583 param_name = ParameterNameAt(has_receiver - kClosure + i); 6504 param_name = ParameterNameAt(has_receiver - kClosure + i);
6584 closure_function.SetParameterNameAt(i, param_name); 6505 closure_function.SetParameterNameAt(i, param_name);
6585 } 6506 }
6586 6507 const FunctionType& signature_type =
6587 // Lookup or create a new signature class for the closure function in the 6508 FunctionType::Handle(closure_function.SignatureType());
6588 // library of the owner class.
6589 const Class& owner_class = Class::Handle(Owner());
6590 ASSERT(!owner_class.IsNull() && (Owner() == closure_function.Owner()));
6591 const Library& library = Library::Handle(owner_class.library());
6592 ASSERT(!library.IsNull());
6593 const String& signature = String::Handle(closure_function.Signature());
6594 Class& signature_class = Class::ZoneHandle(
6595 library.LookupLocalClass(signature));
6596 if (signature_class.IsNull()) {
6597 const Script& script = Script::Handle(this->script());
6598 signature_class = Class::NewSignatureClass(signature,
6599 closure_function,
6600 script,
6601 closure_function.token_pos());
6602 library.AddClass(signature_class);
6603 } else {
6604 closure_function.set_signature_class(signature_class);
6605 }
6606 // Finalize types in signature class here, so that the
6607 // signature type is not computed twice.
6608 ClassFinalizer::FinalizeTypesInClass(signature_class);
6609 const Type& signature_type = Type::Handle(signature_class.SignatureType());
6610 if (!signature_type.IsFinalized()) { 6509 if (!signature_type.IsFinalized()) {
6611 ClassFinalizer::FinalizeType( 6510 ClassFinalizer::FinalizeType(
6612 signature_class, signature_type, ClassFinalizer::kCanonicalize); 6511 Class::Handle(Owner()), signature_type, ClassFinalizer::kCanonicalize);
6613 } 6512 }
6614 ASSERT(closure_function.signature_class() == signature_class.raw());
6615 set_implicit_closure_function(closure_function); 6513 set_implicit_closure_function(closure_function);
6616 ASSERT(closure_function.IsImplicitClosureFunction()); 6514 ASSERT(closure_function.IsImplicitClosureFunction());
6617 return closure_function.raw(); 6515 return closure_function.raw();
6618 } 6516 }
6619 6517
6620 6518
6621 void Function::DropUncompiledImplicitClosureFunction() const { 6519 void Function::DropUncompiledImplicitClosureFunction() const {
6622 if (implicit_closure_function() != Function::null()) { 6520 if (implicit_closure_function() != Function::null()) {
6623 const Function& func = Function::Handle(implicit_closure_function()); 6521 const Function& func = Function::Handle(implicit_closure_function());
6624 if (!func.HasCode()) { 6522 if (!func.HasCode()) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
6709 RawInstance* Function::ImplicitStaticClosure() const { 6607 RawInstance* Function::ImplicitStaticClosure() const {
6710 if (implicit_static_closure() == Instance::null()) { 6608 if (implicit_static_closure() == Instance::null()) {
6711 Thread* thread = Thread::Current(); 6609 Thread* thread = Thread::Current();
6712 Isolate* isolate = thread->isolate(); 6610 Isolate* isolate = thread->isolate();
6713 Zone* zone = thread->zone(); 6611 Zone* zone = thread->zone();
6714 ObjectStore* object_store = isolate->object_store(); 6612 ObjectStore* object_store = isolate->object_store();
6715 const Context& context = 6613 const Context& context =
6716 Context::Handle(zone, object_store->empty_context()); 6614 Context::Handle(zone, object_store->empty_context());
6717 Instance& closure = 6615 Instance& closure =
6718 Instance::Handle(zone, Closure::New(*this, context, Heap::kOld)); 6616 Instance::Handle(zone, Closure::New(*this, context, Heap::kOld));
6719 const char* error_str = NULL;
6720 closure ^= closure.CheckAndCanonicalize(&error_str);
6721 ASSERT(!closure.IsNull());
6722 set_implicit_static_closure(closure); 6617 set_implicit_static_closure(closure);
6723 } 6618 }
6724 return implicit_static_closure(); 6619 return implicit_static_closure();
6725 } 6620 }
6726 6621
6727 6622
6728 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const { 6623 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const {
6729 ASSERT(IsImplicitClosureFunction()); 6624 ASSERT(IsImplicitClosureFunction());
6730 const Class& cls = Class::Handle(signature_class()); 6625 const FunctionType& signature_type = FunctionType::Handle(SignatureType());
6626 const Class& cls = Class::Handle(signature_type.type_class());
6731 const Context& context = Context::Handle(Context::New(1)); 6627 const Context& context = Context::Handle(Context::New(1));
6732 context.SetAt(0, receiver); 6628 context.SetAt(0, receiver);
6733 const Instance& result = Instance::Handle(Closure::New(*this, context)); 6629 const Instance& result = Instance::Handle(Closure::New(*this, context));
6734 if (cls.NumTypeArguments() > 0) { 6630 if (cls.IsGeneric()) {
6735 const TypeArguments& type_arguments = 6631 const TypeArguments& type_arguments =
6736 TypeArguments::Handle(receiver.GetTypeArguments()); 6632 TypeArguments::Handle(receiver.GetTypeArguments());
6737 result.SetTypeArguments(type_arguments); 6633 result.SetTypeArguments(type_arguments);
6738 } 6634 }
6739 return result.raw(); 6635 return result.raw();
6740 } 6636 }
6741 6637
6742 6638
6743 RawString* Function::BuildSignature(bool instantiate, 6639 RawString* Function::BuildSignature(bool instantiate,
6744 NameVisibility name_visibility, 6640 NameVisibility name_visibility,
6745 const TypeArguments& instantiator) const { 6641 const TypeArguments& instantiator) const {
6746 Thread* thread = Thread::Current(); 6642 Thread* thread = Thread::Current();
6747 Zone* zone = thread->zone(); 6643 Zone* zone = thread->zone();
6748 GrowableHandlePtrArray<const String> pieces(zone, 4); 6644 GrowableHandlePtrArray<const String> pieces(zone, 4);
6749 String& name = String::Handle(zone); 6645 String& name = String::Handle(zone);
6750 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { 6646 if (!instantiate && !is_static() && (name_visibility == kInternalName)) {
6751 // Prefix the signature with its signature class and type parameters, if any 6647 // Prefix the signature with its scope class and type parameters, if any
6752 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the 6648 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the
6753 // signature class name is the alias name. 6649 // scope class name is the alias name.
6754 // The signature of static functions cannot be type parameterized. 6650 // The signature of static functions cannot be type parameterized.
6755 const Class& function_class = Class::Handle(zone, Owner()); 6651 const Class& scope_class = Class::Handle(zone, Owner());
6756 ASSERT(!function_class.IsNull()); 6652 ASSERT(!scope_class.IsNull());
6757 const TypeArguments& type_parameters = TypeArguments::Handle( 6653 if (scope_class.IsGeneric()) {
6758 zone, function_class.type_parameters()); 6654 const TypeArguments& type_parameters = TypeArguments::Handle(
6759 if (!type_parameters.IsNull()) { 6655 zone, scope_class.type_parameters());
6760 const String& function_class_name = 6656 const String& scope_class_name = String::Handle(zone, scope_class.Name());
6761 String::Handle(zone, function_class.Name()); 6657 pieces.Add(scope_class_name);
6762 pieces.Add(function_class_name);
6763 const intptr_t num_type_parameters = type_parameters.Length(); 6658 const intptr_t num_type_parameters = type_parameters.Length();
6764 pieces.Add(Symbols::LAngleBracket()); 6659 pieces.Add(Symbols::LAngleBracket());
6765 TypeParameter& type_parameter = TypeParameter::Handle(zone); 6660 TypeParameter& type_parameter = TypeParameter::Handle(zone);
6766 AbstractType& bound = AbstractType::Handle(zone); 6661 AbstractType& bound = AbstractType::Handle(zone);
6767 for (intptr_t i = 0; i < num_type_parameters; i++) { 6662 for (intptr_t i = 0; i < num_type_parameters; i++) {
6768 type_parameter ^= type_parameters.TypeAt(i); 6663 type_parameter ^= type_parameters.TypeAt(i);
6769 name = type_parameter.name(); 6664 name = type_parameter.name();
6770 pieces.Add(name); 6665 pieces.Add(name);
6771 bound = type_parameter.bound(); 6666 bound = type_parameter.bound();
6772 if (!bound.IsNull() && !bound.IsObjectType()) { 6667 if (!bound.IsNull() && !bound.IsObjectType()) {
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
7264 ASSERT(raw_ptr()->closure_ == Instance::null()); 7159 ASSERT(raw_ptr()->closure_ == Instance::null());
7265 StorePointer(&raw_ptr()->closure_, closure.raw()); 7160 StorePointer(&raw_ptr()->closure_, closure.raw());
7266 } 7161 }
7267 7162
7268 7163
7269 void ClosureData::set_parent_function(const Function& value) const { 7164 void ClosureData::set_parent_function(const Function& value) const {
7270 StorePointer(&raw_ptr()->parent_function_, value.raw()); 7165 StorePointer(&raw_ptr()->parent_function_, value.raw());
7271 } 7166 }
7272 7167
7273 7168
7274 void ClosureData::set_signature_class(const Class& value) const { 7169 void ClosureData::set_signature_type(const FunctionType& value) const {
7275 StorePointer(&raw_ptr()->signature_class_, value.raw()); 7170 StorePointer(&raw_ptr()->signature_type_, value.raw());
7276 } 7171 }
7277 7172
7278 7173
7279 RawClosureData* ClosureData::New() { 7174 RawClosureData* ClosureData::New() {
7280 ASSERT(Object::closure_data_class() != Class::null()); 7175 ASSERT(Object::closure_data_class() != Class::null());
7281 RawObject* raw = Object::Allocate(ClosureData::kClassId, 7176 RawObject* raw = Object::Allocate(ClosureData::kClassId,
7282 ClosureData::InstanceSize(), 7177 ClosureData::InstanceSize(),
7283 Heap::kOld); 7178 Heap::kOld);
7284 return reinterpret_cast<RawClosureData*>(raw); 7179 return reinterpret_cast<RawClosureData*>(raw);
7285 } 7180 }
(...skipping 3227 matching lines...) Expand 10 before | Expand all | Expand 10 after
10513 if (ref) { 10408 if (ref) {
10514 return; 10409 return;
10515 } 10410 }
10516 jsobj.AddProperty("debuggable", IsDebuggable()); 10411 jsobj.AddProperty("debuggable", IsDebuggable());
10517 { 10412 {
10518 JSONArray jsarr(&jsobj, "classes"); 10413 JSONArray jsarr(&jsobj, "classes");
10519 ClassDictionaryIterator class_iter(*this); 10414 ClassDictionaryIterator class_iter(*this);
10520 Class& klass = Class::Handle(); 10415 Class& klass = Class::Handle();
10521 while (class_iter.HasNext()) { 10416 while (class_iter.HasNext()) {
10522 klass = class_iter.GetNextClass(); 10417 klass = class_iter.GetNextClass();
10523 if (!klass.IsCanonicalSignatureClass() && 10418 if (!klass.IsMixinApplication()) {
10524 !klass.IsMixinApplication()) {
10525 jsarr.AddValue(klass); 10419 jsarr.AddValue(klass);
10526 } 10420 }
10527 } 10421 }
10528 } 10422 }
10529 { 10423 {
10530 JSONArray jsarr(&jsobj, "dependencies"); 10424 JSONArray jsarr(&jsobj, "dependencies");
10531 10425
10532 Array& ports = Array::Handle(); 10426 Array& ports = Array::Handle();
10533 Namespace& ns = Namespace::Handle(); 10427 Namespace& ns = Namespace::Handle();
10534 Library& target = Library::Handle(); 10428 Library& target = Library::Handle();
(...skipping 3845 matching lines...) Expand 10 before | Expand all | Expand 10 after
14380 14274
14381 14275
14382 intptr_t SubtypeTestCache::NumberOfChecks() const { 14276 intptr_t SubtypeTestCache::NumberOfChecks() const {
14383 NoSafepointScope no_safepoint; 14277 NoSafepointScope no_safepoint;
14384 // Do not count the sentinel; 14278 // Do not count the sentinel;
14385 return (Smi::Value(cache()->ptr()->length_) / kTestEntryLength) - 1; 14279 return (Smi::Value(cache()->ptr()->length_) / kTestEntryLength) - 1;
14386 } 14280 }
14387 14281
14388 14282
14389 void SubtypeTestCache::AddCheck( 14283 void SubtypeTestCache::AddCheck(
14390 intptr_t instance_class_id, 14284 const Object& instance_class_id_or_function,
14391 const TypeArguments& instance_type_arguments, 14285 const TypeArguments& instance_type_arguments,
14392 const TypeArguments& instantiator_type_arguments, 14286 const TypeArguments& instantiator_type_arguments,
14393 const Bool& test_result) const { 14287 const Bool& test_result) const {
14394 intptr_t old_num = NumberOfChecks(); 14288 intptr_t old_num = NumberOfChecks();
14395 Array& data = Array::Handle(cache()); 14289 Array& data = Array::Handle(cache());
14396 intptr_t new_len = data.Length() + kTestEntryLength; 14290 intptr_t new_len = data.Length() + kTestEntryLength;
14397 data = Array::Grow(data, new_len); 14291 data = Array::Grow(data, new_len);
14398 set_cache(data); 14292 set_cache(data);
14399 intptr_t data_pos = old_num * kTestEntryLength; 14293 intptr_t data_pos = old_num * kTestEntryLength;
14400 data.SetAt(data_pos + kInstanceClassId, 14294 data.SetAt(data_pos + kInstanceClassIdOrFunction,
14401 Smi::Handle(Smi::New(instance_class_id))); 14295 instance_class_id_or_function);
14402 data.SetAt(data_pos + kInstanceTypeArguments, instance_type_arguments); 14296 data.SetAt(data_pos + kInstanceTypeArguments, instance_type_arguments);
14403 data.SetAt(data_pos + kInstantiatorTypeArguments, 14297 data.SetAt(data_pos + kInstantiatorTypeArguments,
14404 instantiator_type_arguments); 14298 instantiator_type_arguments);
14405 data.SetAt(data_pos + kTestResult, test_result); 14299 data.SetAt(data_pos + kTestResult, test_result);
14406 } 14300 }
14407 14301
14408 14302
14409 void SubtypeTestCache::GetCheck(intptr_t ix, 14303 void SubtypeTestCache::GetCheck(intptr_t ix,
14410 intptr_t* instance_class_id, 14304 Object* instance_class_id_or_function,
14411 TypeArguments* instance_type_arguments, 14305 TypeArguments* instance_type_arguments,
14412 TypeArguments* instantiator_type_arguments, 14306 TypeArguments* instantiator_type_arguments,
14413 Bool* test_result) const { 14307 Bool* test_result) const {
14414 Array& data = Array::Handle(cache()); 14308 Array& data = Array::Handle(cache());
14415 intptr_t data_pos = ix * kTestEntryLength; 14309 intptr_t data_pos = ix * kTestEntryLength;
14416 *instance_class_id = 14310 *instance_class_id_or_function =
14417 Smi::Value(Smi::RawCast(data.At(data_pos + kInstanceClassId))); 14311 data.At(data_pos + kInstanceClassIdOrFunction);
14418 *instance_type_arguments ^= data.At(data_pos + kInstanceTypeArguments); 14312 *instance_type_arguments ^= data.At(data_pos + kInstanceTypeArguments);
14419 *instantiator_type_arguments ^= 14313 *instantiator_type_arguments ^=
14420 data.At(data_pos + kInstantiatorTypeArguments); 14314 data.At(data_pos + kInstantiatorTypeArguments);
14421 *test_result ^= data.At(data_pos + kTestResult); 14315 *test_result ^= data.At(data_pos + kTestResult);
14422 } 14316 }
14423 14317
14424 14318
14425 const char* SubtypeTestCache::ToCString() const { 14319 const char* SubtypeTestCache::ToCString() const {
14426 return "SubtypeTestCache"; 14320 return "SubtypeTestCache";
14427 } 14321 }
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
14956 // Create a canonical object in old space. 14850 // Create a canonical object in old space.
14957 result ^= Object::Clone(result, Heap::kOld); 14851 result ^= Object::Clone(result, Heap::kOld);
14958 } 14852 }
14959 ASSERT(result.IsOld()); 14853 ASSERT(result.IsOld());
14960 cls.InsertCanonicalConstant(index, result); 14854 cls.InsertCanonicalConstant(index, result);
14961 result.SetCanonical(); 14855 result.SetCanonical();
14962 return result.raw(); 14856 return result.raw();
14963 } 14857 }
14964 14858
14965 14859
14966 RawType* Instance::GetType() const { 14860 RawAbstractType* Instance::GetType() const {
14967 if (IsNull()) { 14861 if (IsNull()) {
14968 return Type::NullType(); 14862 return Type::NullType();
14969 } 14863 }
14970 const Class& cls = Class::Handle(clazz()); 14864 const Class& cls = Class::Handle(clazz());
14865 if (cls.IsClosureClass()) {
14866 const Function& signature =
14867 Function::Handle(Closure::Cast(*this).function());
14868 FunctionType& type = FunctionType::Handle(signature.SignatureType());
14869 if (type.scope_class() == cls.raw()) {
14870 // Type is not parameterized.
14871 if (!type.IsCanonical()) {
14872 type ^= type.Canonicalize();
14873 signature.SetSignatureType(type);
14874 }
14875 return type.raw();
14876 }
14877 const Class& scope_cls = Class::Handle(type.scope_class());
14878 ASSERT(scope_cls.NumTypeArguments() > 0);
14879 TypeArguments& type_arguments = TypeArguments::Handle(GetTypeArguments());
14880 type = FunctionType::New(
14881 scope_cls, type_arguments, signature, Scanner::kNoSourcePos);
14882 type.SetIsFinalized();
14883 type ^= type.Canonicalize();
14884 return type.raw();
14885 }
14971 Type& type = Type::Handle(); 14886 Type& type = Type::Handle();
14972 if (!cls.IsGeneric()) { 14887 if (!cls.IsGeneric()) {
14973 type = cls.CanonicalType(); 14888 type = cls.CanonicalType();
14974 } 14889 }
14975 if (type.IsNull()) { 14890 if (type.IsNull()) {
14976 TypeArguments& type_arguments = TypeArguments::Handle(); 14891 TypeArguments& type_arguments = TypeArguments::Handle();
14977 if (cls.NumTypeArguments() > 0) { 14892 if (cls.NumTypeArguments() > 0) {
14978 type_arguments = GetTypeArguments(); 14893 type_arguments = GetTypeArguments();
14979 } 14894 }
14980 type = Type::New(cls, type_arguments, Scanner::kNoSourcePos); 14895 type = Type::New(cls, type_arguments, Scanner::kNoSourcePos);
(...skipping 28 matching lines...) Expand all
15009 Error* bound_error) const { 14924 Error* bound_error) const {
15010 ASSERT(other.IsFinalized()); 14925 ASSERT(other.IsFinalized());
15011 ASSERT(!other.IsDynamicType()); 14926 ASSERT(!other.IsDynamicType());
15012 ASSERT(!other.IsMalformed()); 14927 ASSERT(!other.IsMalformed());
15013 ASSERT(!other.IsMalbounded()); 14928 ASSERT(!other.IsMalbounded());
15014 if (other.IsVoidType()) { 14929 if (other.IsVoidType()) {
15015 return false; 14930 return false;
15016 } 14931 }
15017 Zone* zone = Thread::Current()->zone(); 14932 Zone* zone = Thread::Current()->zone();
15018 const Class& cls = Class::Handle(zone, clazz()); 14933 const Class& cls = Class::Handle(zone, clazz());
14934 if (cls.IsClosureClass()) {
14935 if (other.IsObjectType() || other.IsDartFunctionType()) {
14936 return true;
14937 }
14938 Function& other_signature = Function::Handle(zone);
14939 TypeArguments& other_type_arguments = TypeArguments::Handle(zone);
14940 // Note that we may encounter a bound error in checked mode.
14941 if (!other.IsInstantiated()) {
14942 const AbstractType& instantiated_other = AbstractType::Handle(
14943 zone, other.InstantiateFrom(other_instantiator, bound_error));
14944 if ((bound_error != NULL) && !bound_error->IsNull()) {
14945 ASSERT(Isolate::Current()->flags().type_checks());
14946 return false;
14947 }
14948 if (instantiated_other.IsDynamicType() ||
14949 instantiated_other.IsObjectType() ||
14950 instantiated_other.IsDartFunctionType()) {
14951 return true;
14952 }
14953 if (!instantiated_other.IsFunctionType()) {
14954 return false;
14955 }
14956 other_signature = FunctionType::Cast(instantiated_other).signature();
14957 other_type_arguments = instantiated_other.arguments();
14958 } else {
14959 if (!other.IsFunctionType()) {
14960 return false;
14961 }
14962 other_signature = FunctionType::Cast(other).signature();
14963 other_type_arguments = other.arguments();
14964 }
14965 const Function& signature =
14966 Function::Handle(zone, Closure::Cast(*this).function());
14967 const TypeArguments& type_arguments =
14968 TypeArguments::Handle(zone, GetTypeArguments());
14969 return signature.IsSubtypeOf(type_arguments,
14970 other_signature,
14971 other_type_arguments,
14972 bound_error,
14973 Heap::kOld);
14974 }
15019 TypeArguments& type_arguments = TypeArguments::Handle(zone); 14975 TypeArguments& type_arguments = TypeArguments::Handle(zone);
15020 if (cls.NumTypeArguments() > 0) { 14976 if (cls.NumTypeArguments() > 0) {
15021 type_arguments = GetTypeArguments(); 14977 type_arguments = GetTypeArguments();
15022 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical()); 14978 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical());
15023 // The number of type arguments in the instance must be greater or equal to 14979 // The number of type arguments in the instance must be greater or equal to
15024 // the number of type arguments expected by the instance class. 14980 // the number of type arguments expected by the instance class.
15025 // A discrepancy is allowed for closures, which borrow the type argument 14981 // A discrepancy is allowed for closures, which borrow the type argument
15026 // vector of their instantiator, which may be of a subclass of the class 14982 // vector of their instantiator, which may be of a subclass of the class
15027 // defining the closure. Truncating the vector to the correct length on 14983 // defining the closure. Truncating the vector to the correct length on
15028 // instantiation is unnecessary. The vector may therefore be longer. 14984 // instantiation is unnecessary. The vector may therefore be longer.
15029 // Also, an optimization reuses the type argument vector of the instantiator 14985 // Also, an optimization reuses the type argument vector of the instantiator
15030 // of generic instances when its layout is compatible. 14986 // of generic instances when its layout is compatible.
15031 ASSERT(type_arguments.IsNull() || 14987 ASSERT(type_arguments.IsNull() ||
15032 (type_arguments.Length() >= cls.NumTypeArguments())); 14988 (type_arguments.Length() >= cls.NumTypeArguments()));
15033 } 14989 }
15034 Class& other_class = Class::Handle(zone); 14990 Class& other_class = Class::Handle(zone);
15035 TypeArguments& other_type_arguments = TypeArguments::Handle(zone); 14991 TypeArguments& other_type_arguments = TypeArguments::Handle(zone);
14992 AbstractType& instantiated_other = AbstractType::Handle(zone, other.raw());
15036 // Note that we may encounter a bound error in checked mode. 14993 // Note that we may encounter a bound error in checked mode.
15037 if (!other.IsInstantiated()) { 14994 if (!other.IsInstantiated()) {
15038 const AbstractType& instantiated_other = AbstractType::Handle( 14995 instantiated_other = other.InstantiateFrom(other_instantiator, bound_error);
15039 zone, other.InstantiateFrom(other_instantiator, bound_error));
15040 if ((bound_error != NULL) && !bound_error->IsNull()) { 14996 if ((bound_error != NULL) && !bound_error->IsNull()) {
15041 ASSERT(Isolate::Current()->flags().type_checks()); 14997 ASSERT(Isolate::Current()->flags().type_checks());
15042 return false; 14998 return false;
15043 } 14999 }
15044 other_class = instantiated_other.type_class(); 15000 if (instantiated_other.IsTypeRef()) {
15045 other_type_arguments = instantiated_other.arguments(); 15001 instantiated_other = TypeRef::Cast(instantiated_other).type();
15046 } else { 15002 }
15047 other_class = other.type_class(); 15003 if (instantiated_other.IsDynamicType()) {
15048 other_type_arguments = other.arguments(); 15004 return true;
15005 }
15049 } 15006 }
15007 other_type_arguments = instantiated_other.arguments();
15008 const bool other_is_dart_function = instantiated_other.IsDartFunctionType();
15009 if (other_is_dart_function || instantiated_other.IsFunctionType()) {
15010 // Check if this instance understands a call() method of a compatible type.
15011 Function& call =
15012 Function::Handle(zone, cls.LookupDynamicFunction(Symbols::Call()));
15013 if (call.IsNull()) {
15014 // Walk up the super_class chain.
15015 Class& super_cls = Class::Handle(zone, cls.SuperClass());
15016 while (!super_cls.IsNull() && call.IsNull()) {
15017 call = super_cls.LookupDynamicFunction(Symbols::Call());
15018 super_cls = super_cls.SuperClass();
15019 }
15020 }
15021 if (!call.IsNull()) {
15022 if (other_is_dart_function) {
15023 return true;
15024 }
15025 const Function& other_signature = Function::Handle(
15026 zone, FunctionType::Cast(instantiated_other).signature());
15027 if (call.IsSubtypeOf(type_arguments,
15028 other_signature,
15029 other_type_arguments,
15030 bound_error,
15031 Heap::kOld)) {
15032 return true;
15033 }
15034 }
15035 }
15036 if (!instantiated_other.IsType()) {
15037 return false;
15038 }
15039 other_class = instantiated_other.type_class();
15050 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments, 15040 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments,
15051 bound_error, Heap::kOld); 15041 bound_error, Heap::kOld);
15052 } 15042 }
15053 15043
15054 15044
15055 bool Instance::OperatorEquals(const Instance& other) const { 15045 bool Instance::OperatorEquals(const Instance& other) const {
15056 // TODO(koda): Optimize for all builtin classes and all classes 15046 // TODO(koda): Optimize for all builtin classes and all classes
15057 // that do not override operator==. 15047 // that do not override operator==.
15058 return DartLibraryCalls::Equals(*this, other) == Object::bool_true().raw(); 15048 return DartLibraryCalls::Equals(*this, other) == Object::bool_true().raw();
15059 } 15049 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
15105 native_fields = TypedData::New(kIntPtrCid, NumNativeFields()); 15095 native_fields = TypedData::New(kIntPtrCid, NumNativeFields());
15106 StorePointer(NativeFieldsAddr(), native_fields.raw()); 15096 StorePointer(NativeFieldsAddr(), native_fields.raw());
15107 } 15097 }
15108 for (uint16_t i = 0; i < num_native_fields; i++) { 15098 for (uint16_t i = 0; i < num_native_fields; i++) {
15109 intptr_t byte_offset = i * sizeof(intptr_t); 15099 intptr_t byte_offset = i * sizeof(intptr_t);
15110 TypedData::Cast(native_fields).SetIntPtr(byte_offset, field_values[i]); 15100 TypedData::Cast(native_fields).SetIntPtr(byte_offset, field_values[i]);
15111 } 15101 }
15112 } 15102 }
15113 15103
15114 15104
15115 bool Instance::IsClosure() const {
15116 const Class& cls = Class::Handle(clazz());
15117 return cls.IsSignatureClass();
15118 }
15119
15120
15121 bool Instance::IsCallable(Function* function) const { 15105 bool Instance::IsCallable(Function* function) const {
15122 Class& cls = Class::Handle(clazz()); 15106 Class& cls = Class::Handle(clazz());
15123 if (cls.IsSignatureClass()) { 15107 if (cls.IsClosureClass()) {
15124 if (function != NULL) { 15108 if (function != NULL) {
15125 *function = Closure::function(*this); 15109 *function = Closure::Cast(*this).function();
15126 } 15110 }
15127 return true; 15111 return true;
15128 } 15112 }
15129 // Try to resolve a "call" method. 15113 // Try to resolve a "call" method.
15130 Function& call_function = Function::Handle(); 15114 Function& call_function = Function::Handle();
15131 do { 15115 do {
15132 call_function = cls.LookupDynamicFunction(Symbols::Call()); 15116 call_function = cls.LookupDynamicFunction(Symbols::Call());
15133 if (!call_function.IsNull()) { 15117 if (!call_function.IsNull()) {
15134 if (function != NULL) { 15118 if (function != NULL) {
15135 *function = call_function.raw(); 15119 *function = call_function.raw();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
15220 return "transition_sentinel"; 15204 return "transition_sentinel";
15221 } else if (raw() == Object::unknown_constant().raw()) { 15205 } else if (raw() == Object::unknown_constant().raw()) {
15222 return "unknown_constant"; 15206 return "unknown_constant";
15223 } else if (raw() == Object::non_constant().raw()) { 15207 } else if (raw() == Object::non_constant().raw()) {
15224 return "non_constant"; 15208 return "non_constant";
15225 } else if (Thread::Current()->no_safepoint_scope_depth() > 0) { 15209 } else if (Thread::Current()->no_safepoint_scope_depth() > 0) {
15226 // Can occur when running disassembler. 15210 // Can occur when running disassembler.
15227 return "Instance"; 15211 return "Instance";
15228 } else { 15212 } else {
15229 if (IsClosure()) { 15213 if (IsClosure()) {
15230 return Closure::ToCString(*this); 15214 return Closure::Cast(*this).ToCString();
15231 } 15215 }
15232 const Class& cls = Class::Handle(clazz()); 15216 const Class& cls = Class::Handle(clazz());
15233 TypeArguments& type_arguments = TypeArguments::Handle(); 15217 TypeArguments& type_arguments = TypeArguments::Handle();
15234 const intptr_t num_type_arguments = cls.NumTypeArguments(); 15218 const intptr_t num_type_arguments = cls.NumTypeArguments();
15235 if (num_type_arguments > 0) { 15219 if (num_type_arguments > 0) {
15236 type_arguments = GetTypeArguments(); 15220 type_arguments = GetTypeArguments();
15237 } 15221 }
15238 const Type& type = 15222 const Type& type =
15239 Type::Handle(Type::New(cls, type_arguments, Scanner::kNoSourcePos)); 15223 Type::Handle(Type::New(cls, type_arguments, Scanner::kNoSourcePos));
15240 const String& type_name = String::Handle(type.UserVisibleName()); 15224 const String& type_name = String::Handle(type.UserVisibleName());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
15305 15289
15306 PrintSharedInstanceJSON(&jsobj, ref); 15290 PrintSharedInstanceJSON(&jsobj, ref);
15307 if (IsClosure()) { 15291 if (IsClosure()) {
15308 jsobj.AddProperty("kind", "Closure"); 15292 jsobj.AddProperty("kind", "Closure");
15309 } else { 15293 } else {
15310 jsobj.AddProperty("kind", "PlainInstance"); 15294 jsobj.AddProperty("kind", "PlainInstance");
15311 } 15295 }
15312 jsobj.AddServiceId(*this); 15296 jsobj.AddServiceId(*this);
15313 if (IsClosure()) { 15297 if (IsClosure()) {
15314 jsobj.AddProperty("closureFunction", 15298 jsobj.AddProperty("closureFunction",
15315 Function::Handle(Closure::function(*this))); 15299 Function::Handle(Closure::Cast(*this).function()));
15316 jsobj.AddProperty("closureContext", 15300 jsobj.AddProperty("closureContext",
15317 Context::Handle(Closure::context(*this))); 15301 Context::Handle(Closure::Cast(*this).context()));
15318 } 15302 }
15319 if (ref) { 15303 if (ref) {
15320 return; 15304 return;
15321 } 15305 }
15322 if (IsClosure()) { 15306 if (IsClosure()) {
15323 Debugger* debugger = Isolate::Current()->debugger(); 15307 Debugger* debugger = Isolate::Current()->debugger();
15324 Breakpoint* bpt = debugger->BreakpointAtActivation(*this); 15308 Breakpoint* bpt = debugger->BreakpointAtActivation(*this);
15325 if (bpt != NULL) { 15309 if (bpt != NULL) {
15326 jsobj.AddProperty("_activationBreakpoint", bpt); 15310 jsobj.AddProperty("_activationBreakpoint", bpt);
15327 } 15311 }
15328 } 15312 }
15329 } 15313 }
15330 15314
15331 15315
15332 bool AbstractType::IsResolved() const { 15316 bool AbstractType::IsResolved() const {
15333 // AbstractType is an abstract class. 15317 // AbstractType is an abstract class.
15334 UNREACHABLE(); 15318 UNREACHABLE();
15335 return false; 15319 return false;
15336 } 15320 }
15337 15321
15338 15322
15323 void AbstractType::SetIsResolved() const {
15324 // AbstractType is an abstract class.
15325 UNREACHABLE();
15326 }
15327
15328
15339 bool AbstractType::HasResolvedTypeClass() const { 15329 bool AbstractType::HasResolvedTypeClass() const {
15340 // AbstractType is an abstract class. 15330 // AbstractType is an abstract class.
15341 UNREACHABLE(); 15331 UNREACHABLE();
15342 return false; 15332 return false;
15343 } 15333 }
15344 15334
15345 15335
15346 RawClass* AbstractType::type_class() const { 15336 RawClass* AbstractType::type_class() const {
15347 // AbstractType is an abstract class. 15337 // AbstractType is an abstract class.
15348 UNREACHABLE(); 15338 UNREACHABLE();
15349 return Class::null(); 15339 return Class::null();
15350 } 15340 }
15351 15341
15352 15342
15353 RawUnresolvedClass* AbstractType::unresolved_class() const { 15343 RawUnresolvedClass* AbstractType::unresolved_class() const {
15354 // AbstractType is an abstract class. 15344 // AbstractType is an abstract class.
15355 UNREACHABLE(); 15345 UNREACHABLE();
15356 return UnresolvedClass::null(); 15346 return UnresolvedClass::null();
15357 } 15347 }
15358 15348
15359 15349
15360 RawTypeArguments* AbstractType::arguments() const { 15350 RawTypeArguments* AbstractType::arguments() const {
15361 // AbstractType is an abstract class. 15351 // AbstractType is an abstract class.
15362 UNREACHABLE(); 15352 UNREACHABLE();
15363 return NULL; 15353 return NULL;
15364 } 15354 }
15365 15355
15366 15356
15357 void AbstractType::set_arguments(const TypeArguments& value) const {
15358 // AbstractType is an abstract class.
15359 UNREACHABLE();
15360 }
15361
15367 intptr_t AbstractType::token_pos() const { 15362 intptr_t AbstractType::token_pos() const {
15368 // AbstractType is an abstract class. 15363 // AbstractType is an abstract class.
15369 UNREACHABLE(); 15364 UNREACHABLE();
15370 return -1; 15365 return -1;
15371 } 15366 }
15372 15367
15373 15368
15374 bool AbstractType::IsInstantiated(TrailPtr trail) const { 15369 bool AbstractType::IsInstantiated(TrailPtr trail) const {
15375 // AbstractType is an abstract class. 15370 // AbstractType is an abstract class.
15376 UNREACHABLE(); 15371 UNREACHABLE();
15377 return false; 15372 return false;
15378 } 15373 }
15379 15374
15380 15375
15381 bool AbstractType::IsFinalized() const { 15376 bool AbstractType::IsFinalized() const {
15382 // AbstractType is an abstract class. 15377 // AbstractType is an abstract class.
15383 UNREACHABLE(); 15378 UNREACHABLE();
15384 return false; 15379 return false;
15385 } 15380 }
15386 15381
15387 15382
15383 void AbstractType::SetIsFinalized() const {
15384 // AbstractType is an abstract class.
15385 UNREACHABLE();
15386 }
15387
15388
15388 bool AbstractType::IsBeingFinalized() const { 15389 bool AbstractType::IsBeingFinalized() const {
15389 // AbstractType is an abstract class. 15390 // AbstractType is an abstract class.
15390 UNREACHABLE(); 15391 UNREACHABLE();
15391 return false; 15392 return false;
15392 } 15393 }
15393 15394
15394 15395
15396 void AbstractType::SetIsBeingFinalized() const {
15397 // AbstractType is an abstract class.
15398 UNREACHABLE();
15399 }
15400
15401
15395 bool AbstractType::IsMalformed() const { 15402 bool AbstractType::IsMalformed() const {
15396 // AbstractType is an abstract class. 15403 // AbstractType is an abstract class.
15397 UNREACHABLE(); 15404 UNREACHABLE();
15398 return false; 15405 return false;
15399 } 15406 }
15400 15407
15401 15408
15402 bool AbstractType::IsMalbounded() const { 15409 bool AbstractType::IsMalbounded() const {
15403 // AbstractType is an abstract class. 15410 // AbstractType is an abstract class.
15404 UNREACHABLE(); 15411 UNREACHABLE();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
15539 if (IsTypeParameter()) { 15546 if (IsTypeParameter()) {
15540 return TypeParameter::Cast(*this).name(); 15547 return TypeParameter::Cast(*this).name();
15541 } 15548 }
15542 // If the type is still being finalized, we may be reporting an error about 15549 // If the type is still being finalized, we may be reporting an error about
15543 // a malformed type, so proceed with caution. 15550 // a malformed type, so proceed with caution.
15544 const TypeArguments& args = TypeArguments::Handle(zone, arguments()); 15551 const TypeArguments& args = TypeArguments::Handle(zone, arguments());
15545 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); 15552 const intptr_t num_args = args.IsNull() ? 0 : args.Length();
15546 String& class_name = String::Handle(zone); 15553 String& class_name = String::Handle(zone);
15547 intptr_t first_type_param_index; 15554 intptr_t first_type_param_index;
15548 intptr_t num_type_params; // Number of type parameters to print. 15555 intptr_t num_type_params; // Number of type parameters to print.
15549 if (HasResolvedTypeClass()) { 15556 Class& cls = Class::Handle(zone);
15550 const Class& cls = Class::Handle(zone, type_class()); 15557 if (IsFunctionType()) {
15558 cls = type_class();
15559 if (!cls.IsTypedefClass()) {
15560 const Function& signature_function = Function::Handle(
15561 zone, FunctionType::Cast(*this).signature());
15562 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) {
15563 return signature_function.UserVisibleSignature();
15564 }
15565 return signature_function.InstantiatedSignatureFrom(args,
15566 name_visibility);
15567 }
15568 class_name = cls.Name(); // Typedef name.
15569 // We may be reporting an error about a malformed function type. In that
15570 // case, avoid instantiating the signature, since it may cause divergence.
15571 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) {
15572 return class_name.raw();
15573 }
15574 // Print the name of a typedef as a regular, possibly parameterized, class.
15575 } else if (HasResolvedTypeClass()) {
15576 cls = type_class();
15577 }
15578 if (!cls.IsNull()) {
15551 if (IsResolved() || !cls.IsMixinApplication()) { 15579 if (IsResolved() || !cls.IsMixinApplication()) {
15552 // Do not print the full vector, but only the declared type parameters. 15580 // Do not print the full vector, but only the declared type parameters.
15553 num_type_params = cls.NumTypeParameters(); 15581 num_type_params = cls.NumTypeParameters();
15554 } else { 15582 } else {
15555 // Do not print the type parameters of an unresolved mixin application, 15583 // Do not print the type parameters of an unresolved mixin application,
15556 // since it would prematurely trigger the application of the mixin type. 15584 // since it would prematurely trigger the application of the mixin type.
15557 num_type_params = 0; 15585 num_type_params = 0;
15558 } 15586 }
15559 if (name_visibility == kInternalName) { 15587 if (name_visibility == kInternalName) {
15560 class_name = cls.Name(); 15588 class_name = cls.Name();
(...skipping 17 matching lines...) Expand all
15578 } 15606 }
15579 } else { 15607 } else {
15580 // The actual type argument vector can be longer than necessary, because 15608 // The actual type argument vector can be longer than necessary, because
15581 // of type optimizations. 15609 // of type optimizations.
15582 if (IsFinalized() && cls.is_type_finalized()) { 15610 if (IsFinalized() && cls.is_type_finalized()) {
15583 first_type_param_index = cls.NumTypeArguments() - num_type_params; 15611 first_type_param_index = cls.NumTypeArguments() - num_type_params;
15584 } else { 15612 } else {
15585 first_type_param_index = num_args - num_type_params; 15613 first_type_param_index = num_args - num_type_params;
15586 } 15614 }
15587 } 15615 }
15588 if (cls.IsSignatureClass()) {
15589 // We may be reporting an error about a malformed function type. In that
15590 // case, avoid instantiating the signature, since it may cause divergence.
15591 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) {
15592 return class_name.raw();
15593 }
15594 // To avoid divergence, print the name of a typedef (non-canonical
15595 // signature class) as a regular, possibly parameterized, class.
15596 if (cls.IsCanonicalSignatureClass()) {
15597 const Function& signature_function = Function::Handle(
15598 zone, cls.signature_function());
15599 // Signature classes have no super type, however, they take as many
15600 // type arguments as the owner class of their signature function (if it
15601 // is non static and generic, see Class::NumTypeArguments()). Therefore,
15602 // first_type_param_index may be greater than 0 here.
15603 return signature_function.InstantiatedSignatureFrom(args,
15604 name_visibility);
15605 }
15606 }
15607 } else { 15616 } else {
15608 const UnresolvedClass& cls = 15617 class_name = UnresolvedClass::Handle(zone, unresolved_class()).Name();
15609 UnresolvedClass::Handle(zone, unresolved_class());
15610 class_name = cls.Name();
15611 num_type_params = num_args; 15618 num_type_params = num_args;
15612 first_type_param_index = 0; 15619 first_type_param_index = 0;
15613 } 15620 }
15614 GrowableHandlePtrArray<const String> pieces(zone, 4); 15621 GrowableHandlePtrArray<const String> pieces(zone, 4);
15615 pieces.Add(class_name); 15622 pieces.Add(class_name);
15616 if ((num_type_params == 0) || 15623 if ((num_type_params == 0) ||
15617 args.IsRaw(first_type_param_index, num_type_params)) { 15624 args.IsRaw(first_type_param_index, num_type_params)) {
15618 // Do nothing. 15625 // Do nothing.
15619 } else { 15626 } else {
15620 const String& args_name = String::Handle(zone, 15627 const String& args_name = String::Handle(zone,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
15692 (type_class() == Type::Handle(Type::SmiType()).type_class()); 15699 (type_class() == Type::Handle(Type::SmiType()).type_class());
15693 } 15700 }
15694 15701
15695 15702
15696 bool AbstractType::IsStringType() const { 15703 bool AbstractType::IsStringType() const {
15697 return HasResolvedTypeClass() && 15704 return HasResolvedTypeClass() &&
15698 (type_class() == Type::Handle(Type::StringType()).type_class()); 15705 (type_class() == Type::Handle(Type::StringType()).type_class());
15699 } 15706 }
15700 15707
15701 15708
15702 bool AbstractType::IsFunctionType() const { 15709 bool AbstractType::IsDartFunctionType() const {
15703 return HasResolvedTypeClass() && 15710 return HasResolvedTypeClass() &&
15704 (type_class() == Type::Handle(Type::Function()).type_class()); 15711 (type_class() == Type::Handle(Type::Function()).type_class());
15705 } 15712 }
15706 15713
15707 15714
15708 bool AbstractType::TypeTest(TypeTestKind test_kind, 15715 bool AbstractType::TypeTest(TypeTestKind test_kind,
15709 const AbstractType& other, 15716 const AbstractType& other,
15710 Error* bound_error, 15717 Error* bound_error,
15711 Heap::Space space) const { 15718 Heap::Space space) const {
15712 ASSERT(IsFinalized()); 15719 ASSERT(IsFinalized());
(...skipping 17 matching lines...) Expand all
15730 } 15737 }
15731 return false; 15738 return false;
15732 } 15739 }
15733 if (other.IsMalbounded()) { 15740 if (other.IsMalbounded()) {
15734 ASSERT(Isolate::Current()->flags().type_checks()); 15741 ASSERT(Isolate::Current()->flags().type_checks());
15735 if ((bound_error != NULL) && bound_error->IsNull()) { 15742 if ((bound_error != NULL) && bound_error->IsNull()) {
15736 *bound_error = other.error(); 15743 *bound_error = other.error();
15737 } 15744 }
15738 return false; 15745 return false;
15739 } 15746 }
15747 if (other.IsObjectType() || other.IsDynamicType()) {
15748 return true;
15749 }
15740 if (IsBoundedType() || other.IsBoundedType()) { 15750 if (IsBoundedType() || other.IsBoundedType()) {
15741 if (Equals(other)) { 15751 if (Equals(other)) {
15742 return true; 15752 return true;
15743 } 15753 }
15744 // Redundant check if other type is equal to the upper bound of this type. 15754 // Redundant check if other type is equal to the upper bound of this type.
15745 if (IsBoundedType() && 15755 if (IsBoundedType() &&
15746 AbstractType::Handle(BoundedType::Cast(*this).bound()).Equals(other)) { 15756 AbstractType::Handle(BoundedType::Cast(*this).bound()).Equals(other)) {
15747 return true; 15757 return true;
15748 } 15758 }
15749 return false; // TODO(regis): We should return "maybe after instantiation". 15759 return false; // TODO(regis): We should return "maybe after instantiation".
15750 } 15760 }
15761 Zone* zone = Thread::Current()->zone();
15751 // Type parameters cannot be handled by Class::TypeTest(). 15762 // Type parameters cannot be handled by Class::TypeTest().
15752 // When comparing two uninstantiated function types, one returning type 15763 // When comparing two uninstantiated function types, one returning type
15753 // parameter K, the other returning type parameter V, we cannot assume that K 15764 // parameter K, the other returning type parameter V, we cannot assume that K
15754 // is a subtype of V, or vice versa. We only return true if K equals V, as 15765 // is a subtype of V, or vice versa. We only return true if K equals V, as
15755 // defined by TypeParameter::Equals. 15766 // defined by TypeParameter::Equals.
15756 // The same rule applies when checking the upper bound of a still 15767 // The same rule applies when checking the upper bound of a still
15757 // uninstantiated type at compile time. Returning false will defer the test 15768 // uninstantiated type at compile time. Returning false will defer the test
15758 // to run time. 15769 // to run time.
15759 // There are however some cases can be decided at compile time. 15770 // There are however some cases that can be decided at compile time.
15760 // For example, with class A<K, V extends K>, new A<T, T> called from within 15771 // For example, with class A<K, V extends K>, new A<T, T> called from within
15761 // a class B<T> will never require a run time bound check, even if T is 15772 // a class B<T> will never require a run time bound check, even if T is
15762 // uninstantiated at compile time. 15773 // uninstantiated at compile time.
15763 if (IsTypeParameter()) { 15774 if (IsTypeParameter()) {
15764 const TypeParameter& type_param = TypeParameter::Cast(*this); 15775 const TypeParameter& type_param = TypeParameter::Cast(*this);
15765 if (other.IsTypeParameter()) { 15776 if (other.IsTypeParameter()) {
15766 const TypeParameter& other_type_param = TypeParameter::Cast(other); 15777 const TypeParameter& other_type_param = TypeParameter::Cast(other);
15767 if (type_param.Equals(other_type_param)) { 15778 if (type_param.Equals(other_type_param)) {
15768 return true; 15779 return true;
15769 } 15780 }
15770 } 15781 }
15771 const AbstractType& bound = AbstractType::Handle(type_param.bound()); 15782 const AbstractType& bound = AbstractType::Handle(zone, type_param.bound());
15772 // We may be checking bounds at finalization time and can encounter 15783 // We may be checking bounds at finalization time and can encounter
15773 // a still unfinalized bound. Finalizing the bound here may lead to cycles. 15784 // a still unfinalized bound. Finalizing the bound here may lead to cycles.
15774 if (!bound.IsFinalized()) { 15785 if (!bound.IsFinalized()) {
15775 return false; // TODO(regis): Return "maybe after instantiation". 15786 return false; // TODO(regis): Return "maybe after instantiation".
15776 } 15787 }
15777 if (bound.IsMoreSpecificThan(other, bound_error)) { 15788 if (bound.IsMoreSpecificThan(other, bound_error)) {
15778 return true; 15789 return true;
15779 } 15790 }
15780 return false; // TODO(regis): We should return "maybe after instantiation". 15791 return false; // TODO(regis): We should return "maybe after instantiation".
15781 } 15792 }
15782 if (other.IsTypeParameter()) { 15793 if (other.IsTypeParameter()) {
15783 return false; // TODO(regis): We should return "maybe after instantiation". 15794 return false; // TODO(regis): We should return "maybe after instantiation".
15784 } 15795 }
15785 const Class& cls = Class::Handle(type_class()); 15796 const Class& type_cls = Class::Handle(zone, type_class());
15786 return cls.TypeTest(test_kind, 15797 // Function types cannot be handled by Class::TypeTest().
15787 TypeArguments::Handle(arguments()), 15798 const bool other_is_dart_function_type = other.IsDartFunctionType();
15788 Class::Handle(other.type_class()), 15799 if (other_is_dart_function_type || other.IsFunctionType()) {
15789 TypeArguments::Handle(other.arguments()), 15800 if (IsFunctionType()) {
15790 bound_error, 15801 if (other_is_dart_function_type) {
15791 space); 15802 return true;
15803 }
15804 const Function& other_fun =
15805 Function::Handle(zone, FunctionType::Cast(other).signature());
15806 // Check for two function types.
15807 const Function& fun =
15808 Function::Handle(zone, FunctionType::Cast(*this).signature());
15809 return fun.TypeTest(test_kind,
15810 TypeArguments::Handle(zone, arguments()),
15811 other_fun,
15812 TypeArguments::Handle(zone, other.arguments()),
15813 bound_error,
15814 space);
15815 }
15816 // Check if type S has a call() method of function type T.
15817 Function& function =
15818 Function::Handle(zone, type_cls.LookupDynamicFunction(Symbols::Call()));
15819 if (function.IsNull()) {
15820 // Walk up the super_class chain.
15821 Class& cls = Class::Handle(zone, type_cls.SuperClass());
15822 while (!cls.IsNull() && function.IsNull()) {
15823 function = cls.LookupDynamicFunction(Symbols::Call());
15824 cls = cls.SuperClass();
15825 }
15826 }
15827 if (!function.IsNull()) {
15828 if (other_is_dart_function_type ||
15829 function.TypeTest(test_kind,
15830 TypeArguments::Handle(zone, arguments()),
15831 Function::Handle(
15832 zone, FunctionType::Cast(other).signature()),
15833 TypeArguments::Handle(zone, other.arguments()),
15834 bound_error,
15835 space)) {
15836 return true;
15837 }
15838 }
15839 }
15840 if (IsFunctionType()) {
15841 return false;
15842 }
15843 return type_cls.TypeTest(test_kind,
15844 TypeArguments::Handle(zone, arguments()),
15845 Class::Handle(zone, other.type_class()),
15846 TypeArguments::Handle(zone, other.arguments()),
15847 bound_error,
15848 space);
15792 } 15849 }
15793 15850
15794 15851
15795 intptr_t AbstractType::Hash() const { 15852 intptr_t AbstractType::Hash() const {
15796 // AbstractType is an abstract class. 15853 // AbstractType is an abstract class.
15797 UNREACHABLE(); 15854 UNREACHABLE();
15798 return 0; 15855 return 0;
15799 } 15856 }
15800 15857
15801 15858
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
15911 ASSERT(!IsFinalized()); 15968 ASSERT(!IsFinalized());
15912 if (IsInstantiated()) { 15969 if (IsInstantiated()) {
15913 ASSERT(HasResolvedTypeClass()); 15970 ASSERT(HasResolvedTypeClass());
15914 set_type_state(RawType::kFinalizedInstantiated); 15971 set_type_state(RawType::kFinalizedInstantiated);
15915 } else { 15972 } else {
15916 set_type_state(RawType::kFinalizedUninstantiated); 15973 set_type_state(RawType::kFinalizedUninstantiated);
15917 } 15974 }
15918 } 15975 }
15919 15976
15920 15977
15921 void Type::ResetIsFinalized() const { 15978 void Type::SetIsBeingFinalized() const {
15922 ASSERT(IsFinalized());
15923 set_type_state(RawType::kBeingFinalized);
15924 SetIsFinalized();
15925 }
15926
15927
15928 void Type::set_is_being_finalized() const {
15929 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized()); 15979 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized());
15930 set_type_state(RawType::kBeingFinalized); 15980 set_type_state(RawType::kBeingFinalized);
15931 } 15981 }
15932 15982
15933 15983
15934 bool Type::IsMalformed() const { 15984 bool Type::IsMalformed() const {
15935 if (raw_ptr()->error_ == LanguageError::null()) { 15985 if (raw_ptr()->error_ == LanguageError::null()) {
15936 return false; 15986 return false;
15937 } 15987 }
15938 const LanguageError& type_error = LanguageError::Handle(error()); 15988 const LanguageError& type_error = LanguageError::Handle(error());
(...skipping 24 matching lines...) Expand all
15963 ASSERT(type_error.kind() == Report::kMalboundedType); 16013 ASSERT(type_error.kind() == Report::kMalboundedType);
15964 return Isolate::Current()->flags().type_checks(); 16014 return Isolate::Current()->flags().type_checks();
15965 } 16015 }
15966 16016
15967 16017
15968 void Type::set_error(const LanguageError& value) const { 16018 void Type::set_error(const LanguageError& value) const {
15969 StorePointer(&raw_ptr()->error_, value.raw()); 16019 StorePointer(&raw_ptr()->error_, value.raw());
15970 } 16020 }
15971 16021
15972 16022
15973 void Type::set_is_resolved() const { 16023 void Type::SetIsResolved() const {
15974 ASSERT(!IsResolved()); 16024 ASSERT(!IsResolved());
16025 // A Typedef is a FunctionType, not a type.
16026 ASSERT(!Class::Handle(type_class()).IsTypedefClass());
15975 set_type_state(RawType::kResolved); 16027 set_type_state(RawType::kResolved);
15976 } 16028 }
15977 16029
15978 16030
15979 bool Type::HasResolvedTypeClass() const { 16031 bool Type::HasResolvedTypeClass() const {
15980 const Object& type_class = Object::Handle(raw_ptr()->type_class_); 16032 const Object& type_class = Object::Handle(raw_ptr()->type_class_);
15981 return !type_class.IsNull() && type_class.IsClass(); 16033 return !type_class.IsNull() && type_class.IsClass();
15982 } 16034 }
15983 16035
15984 16036
(...skipping 17 matching lines...) Expand all
16002 ASSERT(!unresolved_class.IsNull()); 16054 ASSERT(!unresolved_class.IsNull());
16003 return unresolved_class.raw(); 16055 return unresolved_class.raw();
16004 #else 16056 #else
16005 ASSERT(!Object::Handle(raw_ptr()->type_class_).IsNull()); 16057 ASSERT(!Object::Handle(raw_ptr()->type_class_).IsNull());
16006 ASSERT(Object::Handle(raw_ptr()->type_class_).IsUnresolvedClass()); 16058 ASSERT(Object::Handle(raw_ptr()->type_class_).IsUnresolvedClass());
16007 return reinterpret_cast<RawUnresolvedClass*>(raw_ptr()->type_class_); 16059 return reinterpret_cast<RawUnresolvedClass*>(raw_ptr()->type_class_);
16008 #endif 16060 #endif
16009 } 16061 }
16010 16062
16011 16063
16012 RawTypeArguments* Type::arguments() const {
16013 return raw_ptr()->arguments_;
16014 }
16015
16016
16017 bool Type::IsInstantiated(TrailPtr trail) const { 16064 bool Type::IsInstantiated(TrailPtr trail) const {
16018 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) { 16065 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) {
16019 return true; 16066 return true;
16020 } 16067 }
16021 if (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated) { 16068 if (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated) {
16022 return false; 16069 return false;
16023 } 16070 }
16024 if (arguments() == TypeArguments::null()) { 16071 if (arguments() == TypeArguments::null()) {
16025 return true; 16072 return true;
16026 } 16073 }
16027 const TypeArguments& args = TypeArguments::Handle(arguments()); 16074 const TypeArguments& args = TypeArguments::Handle(arguments());
16028 intptr_t num_type_args = args.Length(); 16075 intptr_t num_type_args = args.Length();
16029 intptr_t len = num_type_args; // Check the full vector of type args. 16076 intptr_t len = num_type_args; // Check the full vector of type args.
16030 ASSERT(num_type_args > 0); 16077 ASSERT(num_type_args > 0);
16031 // This type is not instantiated if it refers to type parameters. 16078 // This type is not instantiated if it refers to type parameters.
16032 // This IsInstantiated() call may be invoked on an unresolved signature type.
16033 // Although this type may still be unresolved, the type parameters it may 16079 // Although this type may still be unresolved, the type parameters it may
16034 // refer to are resolved by definition. We can therefore return the correct 16080 // refer to are resolved by definition. We can therefore return the correct
16035 // result even for an unresolved type. We just need to look at all type 16081 // result even for an unresolved type. We just need to look at all type
16036 // arguments and not just at the type parameters. 16082 // arguments and not just at the type parameters.
16037 if (HasResolvedTypeClass()) { 16083 if (HasResolvedTypeClass()) {
16038 const Class& cls = Class::Handle(type_class()); 16084 const Class& cls = Class::Handle(type_class());
16039 len = cls.NumTypeArguments(); 16085 len = cls.NumTypeArguments();
16040 ASSERT(num_type_args >= len); // The vector may be longer than necessary. 16086 ASSERT(num_type_args >= len); // The vector may be longer than necessary.
16041 num_type_args = len; 16087 num_type_args = len;
16042 len = cls.NumTypeParameters(); // Check the type parameters only. 16088 len = cls.NumTypeParameters(); // Check the type parameters only.
(...skipping 26 matching lines...) Expand all
16069 ASSERT(IsRecursive()); 16115 ASSERT(IsRecursive());
16070 return instantiated_type.raw(); 16116 return instantiated_type.raw();
16071 } 16117 }
16072 // Note that the type class has to be resolved at this time, but not 16118 // Note that the type class has to be resolved at this time, but not
16073 // necessarily finalized yet. We may be checking bounds at compile time or 16119 // necessarily finalized yet. We may be checking bounds at compile time or
16074 // finalizing the type argument vector of a recursive type. 16120 // finalizing the type argument vector of a recursive type.
16075 const Class& cls = Class::Handle(zone, type_class()); 16121 const Class& cls = Class::Handle(zone, type_class());
16076 16122
16077 // This uninstantiated type is not modified, as it can be instantiated 16123 // This uninstantiated type is not modified, as it can be instantiated
16078 // with different instantiators. Allocate a new instantiated version of it. 16124 // with different instantiators. Allocate a new instantiated version of it.
16079 instantiated_type = Type::New(cls, TypeArguments::Handle(zone), token_pos()); 16125 instantiated_type =
16126 Type::New(cls, TypeArguments::Handle(zone), token_pos(), space);
16080 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments()); 16127 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments());
16081 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); 16128 ASSERT(type_arguments.Length() == cls.NumTypeArguments());
16082 if (type_arguments.IsRecursive()) { 16129 if (type_arguments.IsRecursive()) {
16083 AddOnlyBuddyToTrail(&trail, instantiated_type); 16130 AddOnlyBuddyToTrail(&trail, instantiated_type);
16084 } 16131 }
16085 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, 16132 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments,
16086 bound_error, 16133 bound_error,
16087 trail, 16134 trail,
16088 space); 16135 space);
16089 instantiated_type.set_arguments(type_arguments); 16136 instantiated_type.set_arguments(type_arguments);
16090 if (IsFinalized()) { 16137 if (IsFinalized()) {
16091 instantiated_type.SetIsFinalized(); 16138 instantiated_type.SetIsFinalized();
16092 } else { 16139 } else {
16093 instantiated_type.set_is_resolved(); 16140 instantiated_type.SetIsResolved();
16094 } 16141 }
16095 // Canonicalization is not part of instantiation. 16142 // Canonicalization is not part of instantiation.
16096 return instantiated_type.raw(); 16143 return instantiated_type.raw();
16097 } 16144 }
16098 16145
16099 16146
16100 bool Type::IsEquivalent(const Instance& other, TrailPtr trail) const { 16147 bool Type::IsEquivalent(const Instance& other, TrailPtr trail) const {
16101 ASSERT(!IsNull()); 16148 ASSERT(!IsNull());
16102 if (raw() == other.raw()) { 16149 if (raw() == other.raw()) {
16103 return true; 16150 return true;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
16185 16232
16186 RawAbstractType* Type::CloneUnfinalized() const { 16233 RawAbstractType* Type::CloneUnfinalized() const {
16187 ASSERT(IsResolved()); 16234 ASSERT(IsResolved());
16188 if (IsFinalized()) { 16235 if (IsFinalized()) {
16189 return raw(); 16236 return raw();
16190 } 16237 }
16191 ASSERT(!IsMalformed()); // Malformed types are finalized. 16238 ASSERT(!IsMalformed()); // Malformed types are finalized.
16192 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. 16239 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization.
16193 TypeArguments& type_args = TypeArguments::Handle(arguments()); 16240 TypeArguments& type_args = TypeArguments::Handle(arguments());
16194 type_args = type_args.CloneUnfinalized(); 16241 type_args = type_args.CloneUnfinalized();
16195 const Class& type_cls = Class::Handle(type_class()); 16242 const Type& clone = Type::Handle(
16196 const Type& clone = Type::Handle(Type::New(type_cls, type_args, token_pos())); 16243 Type::New(Class::Handle(type_class()), type_args, token_pos()));
16197 clone.set_is_resolved(); 16244 clone.SetIsResolved();
16198 return clone.raw(); 16245 return clone.raw();
16199 } 16246 }
16200 16247
16201 16248
16202 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner, 16249 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner,
16203 TrailPtr trail) const { 16250 TrailPtr trail) const {
16204 ASSERT(IsFinalized()); 16251 ASSERT(IsFinalized());
16205 ASSERT(!IsMalformed()); 16252 ASSERT(!IsMalformed());
16206 if (IsInstantiated()) { 16253 if (IsInstantiated()) {
16207 return raw(); 16254 return raw();
(...skipping 21 matching lines...) Expand all
16229 16276
16230 RawAbstractType* Type::Canonicalize(TrailPtr trail) const { 16277 RawAbstractType* Type::Canonicalize(TrailPtr trail) const {
16231 ASSERT(IsFinalized()); 16278 ASSERT(IsFinalized());
16232 if (IsCanonical() || IsMalformed()) { 16279 if (IsCanonical() || IsMalformed()) {
16233 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld()); 16280 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld());
16234 return this->raw(); 16281 return this->raw();
16235 } 16282 }
16236 Thread* thread = Thread::Current(); 16283 Thread* thread = Thread::Current();
16237 Zone* zone = thread->zone(); 16284 Zone* zone = thread->zone();
16238 Isolate* isolate = thread->isolate(); 16285 Isolate* isolate = thread->isolate();
16239 Type& type = Type::Handle(zone); 16286 AbstractType& type = Type::Handle(zone);
16240 const Class& cls = Class::Handle(zone, type_class()); 16287 const Class& cls = Class::Handle(zone, type_class());
16288 ASSERT(!cls.IsTypedefClass()); // This type should be a FunctionType.
16241 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) { 16289 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) {
16242 return Object::dynamic_type().raw(); 16290 return Object::dynamic_type().raw();
16243 } 16291 }
16244 // Fast canonical lookup/registry for simple types. 16292 // Fast canonical lookup/registry for simple types.
16245 if (!cls.IsGeneric()) { 16293 if (!cls.IsGeneric() && !cls.IsClosureClass()) {
16246 type = cls.CanonicalType(); 16294 type = cls.CanonicalType();
16247 if (type.IsNull()) { 16295 if (type.IsNull()) {
16248 ASSERT(!cls.raw()->IsVMHeapObject() || (isolate == Dart::vm_isolate())); 16296 ASSERT(!cls.raw()->IsVMHeapObject() || (isolate == Dart::vm_isolate()));
16249 // Canonicalize the type arguments of the supertype, if any. 16297 // Canonicalize the type arguments of the supertype, if any.
16250 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); 16298 TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16251 type_args = type_args.Canonicalize(trail); 16299 type_args = type_args.Canonicalize(trail);
16252 set_arguments(type_args); 16300 set_arguments(type_args);
16253 type = cls.CanonicalType(); // May be set while canonicalizing type args. 16301 type = cls.CanonicalType(); // May be set while canonicalizing type args.
16254 if (type.IsNull()) { 16302 if (type.IsNull()) {
16255 cls.set_canonical_types(*this); 16303 cls.set_canonical_types(*this);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
16320 ASSERT((index == length) || ((index == 1) && (length == 0))); 16368 ASSERT((index == length) || ((index == 1) && (length == 0)));
16321 const intptr_t new_length = (length > 64) ? 16369 const intptr_t new_length = (length > 64) ?
16322 (length + 64) : 16370 (length + 64) :
16323 ((length == 0) ? 2 : (length * 2)); 16371 ((length == 0) ? 2 : (length * 2));
16324 const Array& new_canonical_types = Array::Handle( 16372 const Array& new_canonical_types = Array::Handle(
16325 zone, Array::Grow(canonical_types, new_length, Heap::kOld)); 16373 zone, Array::Grow(canonical_types, new_length, Heap::kOld));
16326 cls.set_canonical_types(new_canonical_types); 16374 cls.set_canonical_types(new_canonical_types);
16327 canonical_types = new_canonical_types.raw(); 16375 canonical_types = new_canonical_types.raw();
16328 } 16376 }
16329 canonical_types.SetAt(index, *this); 16377 canonical_types.SetAt(index, *this);
16330 if ((index == 1) && cls.IsCanonicalSignatureClass()) {
16331 canonical_types.SetAt(0, *this); // Also set canonical signature type at 0.
16332 #ifdef DEBUG
16333 // Verify that the first canonical type is the signature type by checking
16334 // that the type argument vector of the canonical type ends with the
16335 // uninstantiated type parameters of the signature class. Note that these
16336 // type parameters may be bounded if the super class of the owner class
16337 // declares bounds.
16338 // The signature type is finalized during class finalization, before the
16339 // optimizer may canonicalize instantiated function types of the same
16340 // signature class.
16341 // Although the signature class extends class Instance, the type arguments
16342 // of the super class of the owner class of its signature function will be
16343 // prepended to the type argument vector during class finalization.
16344 const TypeArguments& type_params =
16345 TypeArguments::Handle(zone, cls.type_parameters());
16346 const intptr_t num_type_params = cls.NumTypeParameters();
16347 const intptr_t num_type_args = cls.NumTypeArguments();
16348 AbstractType& type_arg = AbstractType::Handle(zone);
16349 TypeParameter& type_param = TypeParameter::Handle(zone);
16350 for (intptr_t i = 0; i < num_type_params; i++) {
16351 type_arg = type_args.TypeAt(num_type_args - num_type_params + i);
16352 while (type_arg.IsBoundedType()) {
16353 type_arg = BoundedType::Cast(type_arg).type();
16354 }
16355 type_param ^= type_params.TypeAt(i);
16356 ASSERT(type_arg.Equals(type_param));
16357 }
16358 #endif
16359 }
16360 ASSERT(IsOld()); 16378 ASSERT(IsOld());
16361 ASSERT(type_args.IsNull() || type_args.IsOld()); 16379 ASSERT(type_args.IsNull() || type_args.IsOld());
16362 SetCanonical(); 16380 SetCanonical();
16363 return this->raw(); 16381 return this->raw();
16364 } 16382 }
16365 16383
16366 16384
16367 intptr_t Type::Hash() const { 16385 intptr_t Type::Hash() const {
16368 ASSERT(IsFinalized()); 16386 ASSERT(IsFinalized());
16369 uint32_t result = 1; 16387 uint32_t result = 1;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
16466 if (ref) { 16484 if (ref) {
16467 return; 16485 return;
16468 } 16486 }
16469 const TypeArguments& typeArgs = TypeArguments::Handle(arguments()); 16487 const TypeArguments& typeArgs = TypeArguments::Handle(arguments());
16470 if (!typeArgs.IsNull()) { 16488 if (!typeArgs.IsNull()) {
16471 jsobj.AddProperty("typeArguments", typeArgs); 16489 jsobj.AddProperty("typeArguments", typeArgs);
16472 } 16490 }
16473 } 16491 }
16474 16492
16475 16493
16494 void FunctionType::SetIsFinalized() const {
16495 ASSERT(!IsFinalized());
16496 if (IsInstantiated()) {
16497 set_type_state(RawFunctionType::kFinalizedInstantiated);
16498 } else {
16499 set_type_state(RawFunctionType::kFinalizedUninstantiated);
16500 }
16501 }
16502
16503
16504 void FunctionType::ResetIsFinalized() const {
16505 ASSERT(IsFinalized());
16506 set_type_state(RawFunctionType::kBeingFinalized);
16507 SetIsFinalized();
16508 }
16509
16510
16511 void FunctionType::SetIsBeingFinalized() const {
16512 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized());
16513 set_type_state(RawFunctionType::kBeingFinalized);
16514 }
16515
16516
16517 bool FunctionType::IsMalformed() const {
16518 if (raw_ptr()->error_ == LanguageError::null()) {
16519 return false;
16520 }
16521 const LanguageError& type_error = LanguageError::Handle(error());
16522 return type_error.kind() == Report::kMalformedType;
16523 }
16524
16525
16526 bool FunctionType::IsMalbounded() const {
16527 if (!Isolate::Current()->flags().type_checks()) {
16528 return false;
16529 }
16530 if (raw_ptr()->error_ == LanguageError::null()) {
16531 return false;
16532 }
16533 const LanguageError& type_error = LanguageError::Handle(error());
16534 return type_error.kind() == Report::kMalboundedType;
16535 }
16536
16537
16538 bool FunctionType::IsMalformedOrMalbounded() const {
16539 if (raw_ptr()->error_ == LanguageError::null()) {
16540 return false;
16541 }
16542 const LanguageError& type_error = LanguageError::Handle(error());
16543 if (type_error.kind() == Report::kMalformedType) {
16544 return true;
16545 }
16546 ASSERT(type_error.kind() == Report::kMalboundedType);
16547 return Isolate::Current()->flags().type_checks();
16548 }
16549
16550
16551 void FunctionType::set_error(const LanguageError& value) const {
16552 StorePointer(&raw_ptr()->error_, value.raw());
16553 }
16554
16555
16556 void FunctionType::SetIsResolved() const {
16557 ASSERT(!IsResolved());
16558 set_type_state(RawFunctionType::kResolved);
16559 }
16560
16561
16562 bool FunctionType::IsInstantiated(TrailPtr trail) const {
16563 if (raw_ptr()->type_state_ == RawFunctionType::kFinalizedInstantiated) {
16564 return true;
16565 }
16566 if (raw_ptr()->type_state_ == RawFunctionType::kFinalizedUninstantiated) {
16567 return false;
16568 }
16569 if (arguments() == TypeArguments::null()) {
16570 return true;
16571 }
16572 const Class& scope_cls = Class::Handle(scope_class());
16573 if (!scope_cls.IsGeneric()) {
16574 ASSERT(scope_cls.IsClosureClass() || scope_cls.IsTypedefClass());
16575 ASSERT(arguments() == TypeArguments::null());
16576 return true;
16577 }
16578 const TypeArguments& type_arguments = TypeArguments::Handle(arguments());
16579 const intptr_t num_type_args = scope_cls.NumTypeArguments();
16580 const intptr_t num_type_params = scope_cls.NumTypeParameters();
16581 // The vector may be longer than necessary. An empty vector is handled above.
16582 ASSERT(type_arguments.Length() >= num_type_args);
16583 return
16584 (num_type_params == 0) ||
16585 type_arguments.IsSubvectorInstantiated(num_type_args - num_type_params,
16586 num_type_params);
16587 }
16588
16589
16590 RawAbstractType* FunctionType::InstantiateFrom(
16591 const TypeArguments& instantiator_type_arguments,
16592 Error* bound_error,
16593 TrailPtr trail,
16594 Heap::Space space) const {
16595 Zone* zone = Thread::Current()->zone();
16596 ASSERT(IsFinalized() || IsBeingFinalized());
16597 ASSERT(!IsInstantiated());
16598 ASSERT(!IsMalformed()); // FunctionType cannot be malformed.
16599 // Instantiating this type with its own type arguments as instantiator can
16600 // occur during finalization and bounds checking. Return the type unchanged.
16601 if (arguments() == instantiator_type_arguments.raw()) {
16602 return raw();
16603 }
16604 // If this type is recursive, we may already be instantiating it.
16605 FunctionType& instantiated_type = FunctionType::Handle(zone);
16606 instantiated_type ^= OnlyBuddyInTrail(trail);
16607 if (!instantiated_type.IsNull()) {
16608 ASSERT(IsRecursive());
16609 return instantiated_type.raw();
16610 }
16611 // Note that the scope class has to be resolved at this time, but not
16612 // necessarily finalized yet. We may be checking bounds at compile time or
16613 // finalizing the type argument vector of a recursive type.
16614 const Class& cls = Class::Handle(zone, scope_class());
16615
16616 // This uninstantiated type is not modified, as it can be instantiated
16617 // with different instantiators. Allocate a new instantiated version of it.
16618 instantiated_type =
16619 FunctionType::New(cls,
16620 TypeArguments::Handle(zone),
16621 Function::Handle(zone, signature()),
16622 token_pos(),
16623 space);
16624 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments());
16625 ASSERT(type_arguments.Length() == cls.NumTypeArguments());
16626 if (type_arguments.IsRecursive()) {
16627 AddOnlyBuddyToTrail(&trail, instantiated_type);
16628 }
16629 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments,
16630 bound_error,
16631 trail,
16632 space);
16633 instantiated_type.set_arguments(type_arguments);
16634 if (IsFinalized()) {
16635 instantiated_type.SetIsFinalized();
16636 } else {
16637 instantiated_type.SetIsResolved();
16638 }
16639 // Canonicalization is not part of instantiation.
16640 return instantiated_type.raw();
16641 }
16642
16643
16644 bool FunctionType::IsEquivalent(const Instance& other, TrailPtr trail) const {
16645 ASSERT(!IsNull());
16646 if (raw() == other.raw()) {
16647 return true;
16648 }
16649 if (!other.IsFunctionType()) {
16650 return false;
16651 }
16652 const FunctionType& other_type = FunctionType::Cast(other);
16653 ASSERT(IsResolved() && other_type.IsResolved());
16654 if (IsMalformed() || other_type.IsMalformed()) {
16655 return false;
16656 }
16657 if (scope_class() != other_type.scope_class()) {
16658 return false;
16659 }
16660 if ((arguments() == other_type.arguments()) &&
16661 (signature() == other_type.signature())) {
16662 return true;
16663 }
16664 if (!IsFinalized() || !other_type.IsFinalized()) {
16665 return false;
16666 }
16667
16668 // We do not instantiate the types of the signature. This happens on demand
16669 // at runtime during a type test.
16670 // Therefore, equal function types must have equal type arguments.
16671 Thread* thread = Thread::Current();
16672 Zone* zone = thread->zone();
16673 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16674 const TypeArguments& other_type_args = TypeArguments::Handle(
16675 zone, other_type.arguments());
16676 if (!type_args.Equals(other_type_args)) {
16677 return false;
16678 }
16679
16680 // Type arguments are equal.
16681 // Equal function types must have equal signature types and equal optional
16682 // named arguments.
16683 if (signature() == other_type.signature()) {
16684 return true;
16685 }
16686 const Function& sig_fun = Function::Handle(zone, signature());
16687 const Function& other_sig_fun = Function::Handle(
16688 zone, other_type.signature());
16689
16690 // Compare number of function parameters.
16691 const intptr_t num_fixed_params = sig_fun.num_fixed_parameters();
16692 const intptr_t other_num_fixed_params = other_sig_fun.num_fixed_parameters();
16693 if (num_fixed_params != other_num_fixed_params) {
16694 return false;
16695 }
16696 const intptr_t num_opt_pos_params = sig_fun.NumOptionalPositionalParameters();
16697 const intptr_t other_num_opt_pos_params =
16698 other_sig_fun.NumOptionalPositionalParameters();
16699 if (num_opt_pos_params != other_num_opt_pos_params) {
16700 return false;
16701 }
16702 const intptr_t num_opt_named_params = sig_fun.NumOptionalNamedParameters();
16703 const intptr_t other_num_opt_named_params =
16704 other_sig_fun.NumOptionalNamedParameters();
16705 if (num_opt_named_params != other_num_opt_named_params) {
16706 return false;
16707 }
16708 const intptr_t num_ignored_params = sig_fun.NumImplicitParameters();
16709 const intptr_t other_num_ignored_params =
16710 other_sig_fun.NumImplicitParameters();
16711 if (num_ignored_params != other_num_ignored_params) {
16712 return false;
16713 }
16714 AbstractType& param_type = Type::Handle(zone);
16715 AbstractType& other_param_type = Type::Handle(zone);
16716 // Check the result type.
16717 param_type = sig_fun.result_type();
16718 other_param_type = other_sig_fun.result_type();
16719 if (!param_type.Equals(other_param_type)) {
16720 return false;
16721 }
16722 // Check the types of all parameters.
16723 const intptr_t num_params = sig_fun.NumParameters();
16724 ASSERT(other_sig_fun.NumParameters() == num_params);
16725 for (intptr_t i = 0; i < num_params; i++) {
16726 param_type = sig_fun.ParameterTypeAt(i);
16727 other_param_type = other_sig_fun.ParameterTypeAt(i);
16728 if (!param_type.Equals(other_param_type)) {
16729 return false;
16730 }
16731 }
16732 // Check the names and types of optional named parameters.
16733 if (num_opt_named_params == 0) {
16734 return true;
16735 }
16736 for (intptr_t i = num_fixed_params; i < num_params; i++) {
16737 if (sig_fun.ParameterNameAt(i) != other_sig_fun.ParameterNameAt(i)) {
16738 return false;
16739 }
16740 }
16741 return true;
16742 }
16743
16744
16745 bool FunctionType::IsRecursive() const {
16746 return TypeArguments::Handle(arguments()).IsRecursive();
16747 }
16748
16749
16750 RawAbstractType* FunctionType::CloneUnfinalized() const {
16751 ASSERT(IsResolved());
16752 if (IsFinalized()) {
16753 return raw();
16754 }
16755 ASSERT(!IsMalformed()); // Malformed types are finalized.
16756 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization.
16757 TypeArguments& type_args = TypeArguments::Handle(arguments());
16758 type_args = type_args.CloneUnfinalized();
16759 const FunctionType& clone = FunctionType::Handle(
16760 FunctionType::New(Class::Handle(scope_class()),
16761 type_args,
16762 Function::Handle(signature()),
16763 token_pos()));
16764 clone.SetIsResolved();
16765 return clone.raw();
16766 }
16767
16768
16769 RawAbstractType* FunctionType::CloneUninstantiated(const Class& new_owner,
16770 TrailPtr trail) const {
16771 ASSERT(IsFinalized());
16772 ASSERT(!IsMalformed());
16773 if (IsInstantiated()) {
16774 return raw();
16775 }
16776 // We may recursively encounter a type already being cloned, because we clone
16777 // the upper bounds of its uninstantiated type arguments in the same pass.
16778 FunctionType& clone = FunctionType::Handle();
16779 clone ^= OnlyBuddyInTrail(trail);
16780 if (!clone.IsNull()) {
16781 return clone.raw();
16782 }
16783 clone = FunctionType::New(Class::Handle(scope_class()),
16784 TypeArguments::Handle(),
16785 Function::Handle(signature()),
16786 token_pos());
16787 TypeArguments& type_args = TypeArguments::Handle(arguments());
16788 // Upper bounds of uninstantiated type arguments may form a cycle.
16789 if (type_args.IsRecursive() || !type_args.IsInstantiated()) {
16790 AddOnlyBuddyToTrail(&trail, clone);
16791 }
16792 type_args = type_args.CloneUninstantiated(new_owner, trail);
16793 clone.set_arguments(type_args);
16794 clone.SetIsFinalized();
16795 return clone.raw();
16796 }
16797
16798
16799 RawAbstractType* FunctionType::Canonicalize(TrailPtr trail) const {
16800 ASSERT(IsFinalized());
16801 if (IsCanonical() || IsMalformed()) {
16802 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld());
16803 return this->raw();
16804 }
16805 Thread* thread = Thread::Current();
16806 Zone* zone = thread->zone();
16807 AbstractType& type = Type::Handle(zone);
16808 const Class& scope_cls = Class::Handle(zone, type_class());
16809 Array& canonical_types = Array::Handle(zone);
16810 canonical_types ^= scope_cls.canonical_types();
16811 if (canonical_types.IsNull()) {
16812 canonical_types = empty_array().raw();
16813 }
16814 intptr_t length = canonical_types.Length();
16815 // Linear search to see whether this type is already present in the
16816 // list of canonicalized types.
16817 // TODO(asiva): Try to re-factor this lookup code to make sharing
16818 // easy between the 4 versions of this loop.
16819 intptr_t index = 1; // Slot 0 is reserved for CanonicalType().
16820 while (index < length) {
16821 type ^= canonical_types.At(index);
16822 if (type.IsNull()) {
16823 break;
16824 }
16825 ASSERT(type.IsFinalized());
16826 if (this->Equals(type)) {
16827 ASSERT(type.IsCanonical());
16828 return type.raw();
16829 }
16830 index++;
16831 }
16832 // The type was not found in the table. It is not canonical yet.
16833
16834 // Canonicalize the type arguments.
16835 TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
16836 // In case the type is first canonicalized at runtime, its type argument
16837 // vector may be longer than necessary. This is not an issue.
16838 ASSERT(type_args.IsNull() ||
16839 (type_args.Length() >= scope_cls.NumTypeArguments()));
16840 type_args = type_args.Canonicalize(trail);
16841 set_arguments(type_args);
16842
16843 // Replace the actual function by a signature function.
16844 const Function& fun = Function::Handle(zone, signature());
16845 if (!fun.IsSignatureFunction()) {
16846 Function& sig_fun =
16847 Function::Handle(zone,
16848 Function::NewSignatureFunction(scope_cls,
16849 Scanner::kNoSourcePos));
16850 type = fun.result_type();
16851 type = type.Canonicalize(trail);
16852 sig_fun.set_result_type(type);
16853 const intptr_t num_params = fun.NumParameters();
16854 sig_fun.set_num_fixed_parameters(fun.num_fixed_parameters());
16855 sig_fun.SetNumOptionalParameters(fun.NumOptionalParameters(),
16856 fun.HasOptionalPositionalParameters());
16857 sig_fun.set_parameter_types(Array::Handle(Array::New(num_params,
16858 Heap::kOld)));
16859 for (intptr_t i = 0; i < num_params; i++) {
16860 type = fun.ParameterTypeAt(i);
16861 type = type.Canonicalize(trail);
16862 sig_fun.SetParameterTypeAt(i, type);
16863 }
16864 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names()));
16865 set_signature(sig_fun);
16866 }
16867
16868 // Canonicalizing the type arguments and the signature may have changed the
16869 // index, may have grown the table, or may even have canonicalized this type.
16870 canonical_types ^= scope_cls.canonical_types();
16871 if (canonical_types.IsNull()) {
16872 canonical_types = empty_array().raw();
16873 }
16874 length = canonical_types.Length();
16875 while (index < length) {
16876 type ^= canonical_types.At(index);
16877 if (type.IsNull()) {
16878 break;
16879 }
16880 ASSERT(type.IsFinalized());
16881 if (this->Equals(type)) {
16882 ASSERT(type.IsCanonical());
16883 return type.raw();
16884 }
16885 index++;
16886 }
16887
16888 // The type needs to be added to the list. Grow the list if it is full.
16889 if (index >= length) {
16890 ASSERT((index == length) || ((index == 1) && (length == 0)));
16891 const intptr_t new_length = (length > 64) ?
16892 (length + 64) :
16893 ((length == 0) ? 2 : (length * 2));
16894 const Array& new_canonical_types = Array::Handle(
16895 zone, Array::Grow(canonical_types, new_length, Heap::kOld));
16896 scope_cls.set_canonical_types(new_canonical_types);
16897 canonical_types = new_canonical_types.raw();
16898 }
16899 canonical_types.SetAt(index, *this);
16900 ASSERT(IsOld());
16901 ASSERT(type_args.IsNull() || type_args.IsOld());
16902 SetCanonical();
16903 return this->raw();
16904 }
16905
16906
16907 intptr_t FunctionType::Hash() const {
16908 ASSERT(IsFinalized());
16909 uint32_t result = 1;
16910 if (IsMalformed()) return result;
16911 result = CombineHashes(result, Class::Handle(scope_class()).id());
16912 result = CombineHashes(result, TypeArguments::Handle(arguments()).Hash());
16913 const Function& sig_fun = Function::Handle(signature());
16914 AbstractType& type = AbstractType::Handle(sig_fun.result_type());
16915 result = CombineHashes(result, type.Hash());
16916 result = CombineHashes(result, sig_fun.NumOptionalPositionalParameters());
16917 const intptr_t num_params = sig_fun.NumParameters();
16918 for (intptr_t i = 0; i < num_params; i++) {
16919 type = sig_fun.ParameterTypeAt(i);
16920 result = CombineHashes(result, type.Hash());
16921 }
16922 if (sig_fun.NumOptionalNamedParameters() > 0) {
16923 String& param_name = String::Handle();
16924 for (intptr_t i = sig_fun.num_fixed_parameters(); i < num_params; i++) {
16925 param_name = sig_fun.ParameterNameAt(i);
16926 result = CombineHashes(result, param_name.Hash());
16927 }
16928 }
16929 return FinalizeHash(result);
16930 }
16931
16932
16933 void FunctionType::set_scope_class(const Class& value) const {
16934 ASSERT(!value.IsNull());
16935 StorePointer(&raw_ptr()->scope_class_, value.raw());
16936 }
16937
16938
16939 void FunctionType::set_arguments(const TypeArguments& value) const {
16940 StorePointer(&raw_ptr()->arguments_, value.raw());
16941 }
16942
16943
16944 void FunctionType::set_signature(const Function& value) const {
16945 StorePointer(&raw_ptr()->signature_, value.raw());
16946 }
16947
16948
16949 RawFunctionType* FunctionType::New(Heap::Space space) {
16950 RawObject* raw = Object::Allocate(FunctionType::kClassId,
16951 FunctionType::InstanceSize(),
16952 space);
16953 return reinterpret_cast<RawFunctionType*>(raw);
16954 }
16955
16956
16957 RawFunctionType* FunctionType::New(const Class& clazz,
16958 const TypeArguments& arguments,
16959 const Function& signature,
16960 intptr_t token_pos,
16961 Heap::Space space) {
16962 const FunctionType& result = FunctionType::Handle(FunctionType::New(space));
16963 result.set_scope_class(clazz);
16964 result.set_arguments(arguments);
16965 result.set_signature(signature);
16966 result.set_token_pos(token_pos);
16967 result.StoreNonPointer(&result.raw_ptr()->type_state_,
16968 RawFunctionType::kAllocated);
16969 return result.raw();
16970 }
16971
16972
16973 void FunctionType::set_token_pos(intptr_t token_pos) const {
16974 ASSERT(Scanner::ValidSourcePosition(token_pos));
16975 StoreNonPointer(&raw_ptr()->token_pos_, token_pos);
16976 }
16977
16978
16979 void FunctionType::set_type_state(int8_t state) const {
16980 ASSERT((state >= RawFunctionType::kAllocated) &&
16981 (state <= RawFunctionType::kFinalizedUninstantiated));
16982 StoreNonPointer(&raw_ptr()->type_state_, state);
16983 }
16984
16985
16986 const char* FunctionType::ToCString() const {
16987 const char* unresolved = IsResolved() ? "" : "Unresolved ";
16988 const Class& scope_cls = Class::Handle(scope_class());
16989 const TypeArguments& type_arguments = TypeArguments::Handle(arguments());
16990 const Function& signature_function = Function::Handle(signature());
16991 const String& signature_string = String::Handle(
16992 signature_function.InstantiatedSignatureFrom(type_arguments,
16993 kInternalName));
16994 if (scope_cls.IsClosureClass()) {
16995 ASSERT(arguments() == TypeArguments::null());
16996 return OS::SCreate(
16997 Thread::Current()->zone(),
16998 "%sFunctionType: %s", unresolved, signature_string.ToCString());
16999 }
17000 const char* class_name = String::Handle(scope_cls.Name()).ToCString();
17001 const char* args_cstr =
17002 type_arguments.IsNull() ? "null" : type_arguments.ToCString();
17003 return OS::SCreate(
17004 Thread::Current()->zone(),
17005 "%s FunctionType: %s (scope_cls: %s, args: %s)",
17006 unresolved,
17007 signature_string.ToCString(),
17008 class_name,
17009 args_cstr);
17010 }
17011
17012
17013 void FunctionType::PrintJSONImpl(JSONStream* stream, bool ref) const {
17014 JSONObject jsobj(stream);
17015 PrintSharedInstanceJSON(&jsobj, ref);
17016 jsobj.AddProperty("kind", "FunctionType");
17017 if (IsCanonical()) {
17018 const Class& scope_cls = Class::Handle(scope_class());
17019 intptr_t id = scope_cls.FindCanonicalTypeIndex(*this);
17020 ASSERT(id >= 0);
17021 intptr_t cid = scope_cls.id();
17022 jsobj.AddFixedServiceId("classes/%" Pd "/types/%" Pd "", cid, id);
17023 jsobj.AddProperty("scopeClass", scope_cls);
17024 } else {
17025 jsobj.AddServiceId(*this);
17026 }
17027 const String& user_name = String::Handle(PrettyName());
17028 const String& vm_name = String::Handle(Name());
17029 AddNameProperties(&jsobj, user_name, vm_name);
17030 if (ref) {
17031 return;
17032 }
17033 const TypeArguments& typeArgs = TypeArguments::Handle(arguments());
17034 if (!typeArgs.IsNull()) {
17035 jsobj.AddProperty("typeArguments", typeArgs);
17036 }
17037 }
17038
17039
16476 bool TypeRef::IsInstantiated(TrailPtr trail) const { 17040 bool TypeRef::IsInstantiated(TrailPtr trail) const {
16477 if (TestAndAddToTrail(&trail)) { 17041 if (TestAndAddToTrail(&trail)) {
16478 return true; 17042 return true;
16479 } 17043 }
16480 return AbstractType::Handle(type()).IsInstantiated(trail); 17044 return AbstractType::Handle(type()).IsInstantiated(trail);
16481 } 17045 }
16482 17046
16483 17047
16484 bool TypeRef::IsEquivalent(const Instance& other, TrailPtr trail) const { 17048 bool TypeRef::IsEquivalent(const Instance& other, TrailPtr trail) const {
16485 if (raw() == other.raw()) { 17049 if (raw() == other.raw()) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
16529 AbstractType& cloned_ref_type = AbstractType::Handle(); 17093 AbstractType& cloned_ref_type = AbstractType::Handle();
16530 cloned_ref_type = ref_type.CloneUninstantiated(new_owner, trail); 17094 cloned_ref_type = ref_type.CloneUninstantiated(new_owner, trail);
16531 ASSERT(!cloned_ref_type.IsTypeRef()); 17095 ASSERT(!cloned_ref_type.IsTypeRef());
16532 cloned_type_ref = TypeRef::New(cloned_ref_type); 17096 cloned_type_ref = TypeRef::New(cloned_ref_type);
16533 AddOnlyBuddyToTrail(&trail, cloned_type_ref); 17097 AddOnlyBuddyToTrail(&trail, cloned_type_ref);
16534 return cloned_type_ref.raw(); 17098 return cloned_type_ref.raw();
16535 } 17099 }
16536 17100
16537 17101
16538 void TypeRef::set_type(const AbstractType& value) const { 17102 void TypeRef::set_type(const AbstractType& value) const {
16539 ASSERT(value.HasResolvedTypeClass()); 17103 ASSERT(value.IsFunctionType() || value.HasResolvedTypeClass());
16540 ASSERT(!value.IsTypeRef()); 17104 ASSERT(!value.IsTypeRef());
16541 StorePointer(&raw_ptr()->type_, value.raw()); 17105 StorePointer(&raw_ptr()->type_, value.raw());
16542 } 17106 }
16543 17107
16544 17108
16545 // A TypeRef cannot be canonical by definition. Only its referenced type can be. 17109 // A TypeRef cannot be canonical by definition. Only its referenced type can be.
16546 // Consider the type Derived, where class Derived extends Base<Derived>. 17110 // Consider the type Derived, where class Derived extends Base<Derived>.
16547 // The first type argument of its flattened type argument vector is Derived, 17111 // The first type argument of its flattened type argument vector is Derived,
16548 // represented by a TypeRef pointing to itself. 17112 // represented by a TypeRef pointing to itself.
16549 RawAbstractType* TypeRef::Canonicalize(TrailPtr trail) const { 17113 RawAbstractType* TypeRef::Canonicalize(TrailPtr trail) const {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
16641 const String& user_name = String::Handle(PrettyName()); 17205 const String& user_name = String::Handle(PrettyName());
16642 const String& vm_name = String::Handle(Name()); 17206 const String& vm_name = String::Handle(Name());
16643 AddNameProperties(&jsobj, user_name, vm_name); 17207 AddNameProperties(&jsobj, user_name, vm_name);
16644 if (ref) { 17208 if (ref) {
16645 return; 17209 return;
16646 } 17210 }
16647 jsobj.AddProperty("targetType", AbstractType::Handle(type())); 17211 jsobj.AddProperty("targetType", AbstractType::Handle(type()));
16648 } 17212 }
16649 17213
16650 17214
16651 void TypeParameter::set_is_finalized() const { 17215 void TypeParameter::SetIsFinalized() const {
16652 ASSERT(!IsFinalized()); 17216 ASSERT(!IsFinalized());
16653 set_type_state(RawTypeParameter::kFinalizedUninstantiated); 17217 set_type_state(RawTypeParameter::kFinalizedUninstantiated);
16654 } 17218 }
16655 17219
16656 17220
16657 bool TypeParameter::IsEquivalent(const Instance& other, TrailPtr trail) const { 17221 bool TypeParameter::IsEquivalent(const Instance& other, TrailPtr trail) const {
16658 if (raw() == other.raw()) { 17222 if (raw() == other.raw()) {
16659 return true; 17223 return true;
16660 } 17224 }
16661 if (other.IsTypeRef()) { 17225 if (other.IsTypeRef()) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
16790 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail); 17354 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail);
16791 const Class& old_owner = Class::Handle(parameterized_class()); 17355 const Class& old_owner = Class::Handle(parameterized_class());
16792 const intptr_t new_index = index() + 17356 const intptr_t new_index = index() +
16793 new_owner.NumTypeArguments() - old_owner.NumTypeArguments(); 17357 new_owner.NumTypeArguments() - old_owner.NumTypeArguments();
16794 const TypeParameter& clone = TypeParameter::Handle( 17358 const TypeParameter& clone = TypeParameter::Handle(
16795 TypeParameter::New(new_owner, 17359 TypeParameter::New(new_owner,
16796 new_index, 17360 new_index,
16797 String::Handle(name()), 17361 String::Handle(name()),
16798 upper_bound, 17362 upper_bound,
16799 token_pos())); 17363 token_pos()));
16800 clone.set_is_finalized(); 17364 clone.SetIsFinalized();
16801 return clone.raw(); 17365 return clone.raw();
16802 } 17366 }
16803 17367
16804 17368
16805 intptr_t TypeParameter::Hash() const { 17369 intptr_t TypeParameter::Hash() const {
16806 ASSERT(IsFinalized()); 17370 ASSERT(IsFinalized());
16807 uint32_t result = Class::Handle(parameterized_class()).id(); 17371 uint32_t result = Class::Handle(parameterized_class()).id();
16808 // No need to include the hash of the bound, since the type parameter is fully 17372 // No need to include the hash of the bound, since the type parameter is fully
16809 // identified by its class and index. 17373 // identified by its class and index.
16810 result = CombineHashes(result, index()); 17374 result = CombineHashes(result, index());
(...skipping 4656 matching lines...) Expand 10 before | Expand all | Expand 10 after
21467 const char* SendPort::ToCString() const { 22031 const char* SendPort::ToCString() const {
21468 return "SendPort"; 22032 return "SendPort";
21469 } 22033 }
21470 22034
21471 22035
21472 void SendPort::PrintJSONImpl(JSONStream* stream, bool ref) const { 22036 void SendPort::PrintJSONImpl(JSONStream* stream, bool ref) const {
21473 Instance::PrintJSONImpl(stream, ref); 22037 Instance::PrintJSONImpl(stream, ref);
21474 } 22038 }
21475 22039
21476 22040
21477 const char* Closure::ToCString(const Instance& closure) { 22041 const char* Closure::ToCString() const {
21478 const Function& fun = Function::Handle(Closure::function(closure)); 22042 const Function& fun = Function::Handle(function());
21479 const bool is_implicit_closure = fun.IsImplicitClosureFunction(); 22043 const bool is_implicit_closure = fun.IsImplicitClosureFunction();
21480 const char* fun_sig = String::Handle(fun.UserVisibleSignature()).ToCString(); 22044 const char* fun_sig = String::Handle(fun.UserVisibleSignature()).ToCString();
21481 const char* from = is_implicit_closure ? " from " : ""; 22045 const char* from = is_implicit_closure ? " from " : "";
21482 const char* fun_desc = is_implicit_closure ? fun.ToCString() : ""; 22046 const char* fun_desc = is_implicit_closure ? fun.ToCString() : "";
21483 return OS::SCreate(Thread::Current()->zone(), 22047 return OS::SCreate(Thread::Current()->zone(),
21484 "Closure: %s%s%s", fun_sig, from, fun_desc); 22048 "Closure: %s%s%s", fun_sig, from, fun_desc);
21485 } 22049 }
21486 22050
21487 22051
21488 RawInstance* Closure::New(const Function& function, 22052 void Closure::PrintJSONImpl(JSONStream* stream, bool ref) const {
21489 const Context& context, 22053 Instance::PrintJSONImpl(stream, ref);
21490 Heap::Space space) { 22054 }
21491 const Class& cls = Class::Handle(function.signature_class()); 22055
21492 ASSERT(cls.instance_size() == Closure::InstanceSize()); 22056
21493 Instance& result = Instance::Handle(); 22057 RawClosure* Closure::New(const Function& function,
22058 const Context& context,
22059 Heap::Space space) {
22060 Closure& result = Closure::Handle();
21494 { 22061 {
21495 RawObject* raw = Object::Allocate(cls.id(), Closure::InstanceSize(), space); 22062 RawObject* raw = Object::Allocate(Closure::kClassId,
22063 Closure::InstanceSize(),
22064 space);
21496 NoSafepointScope no_safepoint; 22065 NoSafepointScope no_safepoint;
21497 result ^= raw; 22066 result ^= raw;
22067 result.StorePointer(&result.raw_ptr()->function_, function.raw());
22068 result.StorePointer(&result.raw_ptr()->context_, context.raw());
21498 } 22069 }
21499 Closure::set_function(result, function);
21500 Closure::set_context(result, context);
21501 return result.raw(); 22070 return result.raw();
21502 } 22071 }
21503 22072
21504 22073
22074 RawClosure* Closure::New() {
22075 RawObject* raw = Object::Allocate(Closure::kClassId,
22076 Closure::InstanceSize(),
22077 Heap::kOld);
22078 return reinterpret_cast<RawClosure*>(raw);
22079 }
22080
22081
21505 intptr_t Stacktrace::Length() const { 22082 intptr_t Stacktrace::Length() const {
21506 const Array& code_array = Array::Handle(raw_ptr()->code_array_); 22083 const Array& code_array = Array::Handle(raw_ptr()->code_array_);
21507 return code_array.Length(); 22084 return code_array.Length();
21508 } 22085 }
21509 22086
21510 22087
21511 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const { 22088 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const {
21512 const Code& code = Code::Handle(CodeAtFrame(frame_index)); 22089 const Code& code = Code::Handle(CodeAtFrame(frame_index));
21513 return code.IsNull() ? Function::null() : code.function(); 22090 return code.IsNull() ? Function::null() : code.function();
21514 } 22091 }
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
22108 return tag_label.ToCString(); 22685 return tag_label.ToCString();
22109 } 22686 }
22110 22687
22111 22688
22112 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 22689 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
22113 Instance::PrintJSONImpl(stream, ref); 22690 Instance::PrintJSONImpl(stream, ref);
22114 } 22691 }
22115 22692
22116 22693
22117 } // namespace dart 22694 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698