OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/class_finalizer.h" | 5 #include "vm/class_finalizer.h" |
6 | 6 |
7 #include "vm/code_generator.h" | 7 #include "vm/code_generator.h" |
8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
9 #include "vm/hash_table.h" | 9 #include "vm/hash_table.h" |
10 #include "vm/heap.h" | 10 #include "vm/heap.h" |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 // of the redirection chain. | 453 // of the redirection chain. |
454 ResolveRedirectingFactoryTarget(target_class, target, visited_factories); | 454 ResolveRedirectingFactoryTarget(target_class, target, visited_factories); |
455 Type& target_type = Type::Handle(target.RedirectionType()); | 455 Type& target_type = Type::Handle(target.RedirectionType()); |
456 Function& target_target = Function::Handle(target.RedirectionTarget()); | 456 Function& target_target = Function::Handle(target.RedirectionTarget()); |
457 if (target_target.IsNull()) { | 457 if (target_target.IsNull()) { |
458 ASSERT(target_type.IsMalformed()); | 458 ASSERT(target_type.IsMalformed()); |
459 } else { | 459 } else { |
460 // If the target type refers to type parameters, substitute them with the | 460 // If the target type refers to type parameters, substitute them with the |
461 // type arguments of the redirection type. | 461 // type arguments of the redirection type. |
462 if (!target_type.IsInstantiated()) { | 462 if (!target_type.IsInstantiated()) { |
| 463 // We do not support generic constructors. |
| 464 ASSERT(target_type.IsInstantiated(kFunctions)); |
463 const TypeArguments& type_args = TypeArguments::Handle(type.arguments()); | 465 const TypeArguments& type_args = TypeArguments::Handle(type.arguments()); |
464 Error& bound_error = Error::Handle(); | 466 Error& bound_error = Error::Handle(); |
465 target_type ^= target_type.InstantiateFrom(type_args, &bound_error, NULL, | 467 target_type ^= |
466 NULL, Heap::kOld); | 468 target_type.InstantiateFrom(type_args, Object::null_type_arguments(), |
| 469 &bound_error, NULL, NULL, Heap::kOld); |
467 if (bound_error.IsNull()) { | 470 if (bound_error.IsNull()) { |
468 target_type ^= FinalizeType(cls, target_type); | 471 target_type ^= FinalizeType(cls, target_type); |
469 } else { | 472 } else { |
470 ASSERT(target_type.IsInstantiated() && type_args.IsInstantiated()); | 473 ASSERT(target_type.IsInstantiated() && type_args.IsInstantiated()); |
471 const Script& script = Script::Handle(target_class.script()); | 474 const Script& script = Script::Handle(target_class.script()); |
472 FinalizeMalformedType(bound_error, script, target_type, | 475 FinalizeMalformedType(bound_error, script, target_type, |
473 "cannot resolve redirecting factory"); | 476 "cannot resolve redirecting factory"); |
474 target_target = Function::null(); | 477 target_target = Function::null(); |
475 } | 478 } |
476 } | 479 } |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 // While finalizing D<T>, the super type arg D<T> (a typeref) gets | 926 // While finalizing D<T>, the super type arg D<T> (a typeref) gets |
924 // instantiated from vector [T], yielding itself. | 927 // instantiated from vector [T], yielding itself. |
925 // | 928 // |
926 if (super_type_arg.IsTypeRef() && super_type_arg.IsBeingFinalized() && | 929 if (super_type_arg.IsTypeRef() && super_type_arg.IsBeingFinalized() && |
927 (super_type_arg.arguments() == arguments.raw())) { | 930 (super_type_arg.arguments() == arguments.raw())) { |
928 arguments.SetTypeAt(i, super_type_arg); | 931 arguments.SetTypeAt(i, super_type_arg); |
929 continue; | 932 continue; |
930 } | 933 } |
931 Error& error = Error::Handle(); | 934 Error& error = Error::Handle(); |
932 super_type_arg = super_type_arg.InstantiateFrom( | 935 super_type_arg = super_type_arg.InstantiateFrom( |
933 arguments, &error, instantiation_trail, NULL, Heap::kOld); | 936 arguments, Object::null_type_arguments(), &error, |
| 937 instantiation_trail, NULL, Heap::kOld); |
934 if (!error.IsNull()) { | 938 if (!error.IsNull()) { |
935 // InstantiateFrom does not report an error if the type is still | 939 // InstantiateFrom does not report an error if the type is still |
936 // uninstantiated. Instead, it will return a new BoundedType so | 940 // uninstantiated. Instead, it will return a new BoundedType so |
937 // that the check is postponed to run time. | 941 // that the check is postponed to run time. |
938 ASSERT(super_type_arg.IsInstantiated()); | 942 ASSERT(super_type_arg.IsInstantiated()); |
939 // Keep only the first bound error. | 943 // Keep only the first bound error. |
940 if (bound_error->IsNull()) { | 944 if (bound_error->IsNull()) { |
941 *bound_error = error.raw(); | 945 *bound_error = error.raw(); |
942 } | 946 } |
943 } | 947 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 type_param.set_bound(declared_bound); | 1024 type_param.set_bound(declared_bound); |
1021 } | 1025 } |
1022 ASSERT(declared_bound.IsFinalized() || declared_bound.IsBeingFinalized()); | 1026 ASSERT(declared_bound.IsFinalized() || declared_bound.IsBeingFinalized()); |
1023 Error& error = Error::Handle(); | 1027 Error& error = Error::Handle(); |
1024 // Note that the bound may be malformed, in which case the bound check | 1028 // Note that the bound may be malformed, in which case the bound check |
1025 // will return an error and the bound check will be postponed to run time. | 1029 // will return an error and the bound check will be postponed to run time. |
1026 if (declared_bound.IsInstantiated()) { | 1030 if (declared_bound.IsInstantiated()) { |
1027 instantiated_bound = declared_bound.raw(); | 1031 instantiated_bound = declared_bound.raw(); |
1028 } else { | 1032 } else { |
1029 instantiated_bound = declared_bound.InstantiateFrom( | 1033 instantiated_bound = declared_bound.InstantiateFrom( |
1030 arguments, &error, NULL, NULL, Heap::kOld); | 1034 arguments, Object::null_type_arguments(), &error, NULL, NULL, |
| 1035 Heap::kOld); |
1031 } | 1036 } |
1032 if (!instantiated_bound.IsFinalized()) { | 1037 if (!instantiated_bound.IsFinalized()) { |
1033 // The bound refers to type parameters, creating a cycle; postpone | 1038 // The bound refers to type parameters, creating a cycle; postpone |
1034 // bound check to run time, when the bound will be finalized. | 1039 // bound check to run time, when the bound will be finalized. |
1035 // The bound may not necessarily be 'IsBeingFinalized' yet, as is the | 1040 // The bound may not necessarily be 'IsBeingFinalized' yet, as is the |
1036 // case with a pair of type parameters of the same class referring to | 1041 // case with a pair of type parameters of the same class referring to |
1037 // each other via their bounds. | 1042 // each other via their bounds. |
1038 type_arg = BoundedType::New(type_arg, instantiated_bound, type_param); | 1043 type_arg = BoundedType::New(type_arg, instantiated_bound, type_param); |
1039 arguments.SetTypeAt(offset + i, type_arg); | 1044 arguments.SetTypeAt(offset + i, type_arg); |
1040 continue; | 1045 continue; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 const Type& fun_type = Type::Cast(type); | 1231 const Type& fun_type = Type::Cast(type); |
1227 const Class& scope_class = Class::Handle(zone, fun_type.type_class()); | 1232 const Class& scope_class = Class::Handle(zone, fun_type.type_class()); |
1228 if (scope_class.IsTypedefClass()) { | 1233 if (scope_class.IsTypedefClass()) { |
1229 Function& signature = | 1234 Function& signature = |
1230 Function::Handle(zone, scope_class.signature_function()); | 1235 Function::Handle(zone, scope_class.signature_function()); |
1231 if (!scope_class.is_type_finalized()) { | 1236 if (!scope_class.is_type_finalized()) { |
1232 FinalizeSignature(scope_class, signature); | 1237 FinalizeSignature(scope_class, signature); |
1233 } | 1238 } |
1234 // If the function type is a generic typedef, instantiate its signature | 1239 // If the function type is a generic typedef, instantiate its signature |
1235 // from its type arguments. | 1240 // from its type arguments. |
1236 // Example: typedef T F<T>(T x) has uninstantiated signature (T x) => T. | 1241 // Example: typedef F<T> = S Function<S>(T x) has uninstantiated |
1237 // The instantiated signature of F(int) becomes (int x) => int. | 1242 // signature (T x) => S. |
| 1243 // The instantiated signature of F(int) becomes (int x) => S. |
1238 // Note that after this step, the signature of the function type is not | 1244 // Note that after this step, the signature of the function type is not |
1239 // identical to the canonical signature of the typedef class anymore. | 1245 // identical to the canonical signature of the typedef class anymore. |
1240 if (scope_class.IsGeneric() && !signature.HasInstantiatedSignature()) { | 1246 if (scope_class.IsGeneric() && !signature.HasInstantiatedSignature()) { |
1241 const TypeArguments& type_args = | |
1242 TypeArguments::Handle(zone, fun_type.arguments()); | |
1243 if (FLAG_trace_type_finalization) { | 1247 if (FLAG_trace_type_finalization) { |
1244 THR_Print("Instantiating signature '%s' of typedef '%s'\n", | 1248 THR_Print("Instantiating signature '%s' of typedef '%s'\n", |
1245 String::Handle(zone, signature.Signature()).ToCString(), | 1249 String::Handle(zone, signature.Signature()).ToCString(), |
1246 String::Handle(zone, fun_type.Name()).ToCString()); | 1250 String::Handle(zone, fun_type.Name()).ToCString()); |
1247 } | 1251 } |
1248 signature = signature.InstantiateSignatureFrom(type_args, Heap::kOld); | 1252 const TypeArguments& instantiator_type_arguments = |
1249 // Note that if type_args contains type parameters, signature is still | 1253 TypeArguments::Handle(zone, fun_type.arguments()); |
1250 // uninstantiated here (typedef type parameters were substituted in | 1254 const TypeArguments& function_type_arguments = |
1251 // the signature with typedef type arguments). | 1255 TypeArguments::Handle(zone, signature.type_parameters()); |
| 1256 signature = signature.InstantiateSignatureFrom( |
| 1257 instantiator_type_arguments, function_type_arguments, Heap::kOld); |
| 1258 // Note that if instantiator_type_arguments contains type parameters, |
| 1259 // as in F<K>, the signature is still uninstantiated (the typedef type |
| 1260 // parameters were substituted in the signature with typedef type |
| 1261 // arguments). Note also that the function type parameters were not |
| 1262 // modified. |
1252 FinalizeSignature(scope_class, signature); // Canonicalize signature. | 1263 FinalizeSignature(scope_class, signature); // Canonicalize signature. |
1253 } | 1264 } |
1254 fun_type.set_signature(signature); | 1265 fun_type.set_signature(signature); |
1255 } else { | 1266 } else { |
1256 FinalizeSignature(cls, Function::Handle(zone, fun_type.signature())); | 1267 FinalizeSignature(cls, Function::Handle(zone, fun_type.signature())); |
1257 } | 1268 } |
1258 } | 1269 } |
1259 | 1270 |
1260 if (FLAG_trace_type_finalization) { | 1271 if (FLAG_trace_type_finalization) { |
1261 THR_Print("Marking type '%s' as finalized for class '%s'\n", | 1272 THR_Print("Marking type '%s' as finalized for class '%s'\n", |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1543 Error& error = Error::Handle(zone); | 1554 Error& error = Error::Handle(zone); |
1544 if (type.IsMalformedOrMalbounded()) { | 1555 if (type.IsMalformedOrMalbounded()) { |
1545 error = type.error(); | 1556 error = type.error(); |
1546 } else { | 1557 } else { |
1547 ASSERT(type.IsInstantiated()); | 1558 ASSERT(type.IsInstantiated()); |
1548 } | 1559 } |
1549 const Instance& const_value = Instance::Handle(zone, field.StaticValue()); | 1560 const Instance& const_value = Instance::Handle(zone, field.StaticValue()); |
1550 if (!error.IsNull() || | 1561 if (!error.IsNull() || |
1551 (!type.IsDynamicType() && | 1562 (!type.IsDynamicType() && |
1552 !const_value.IsInstanceOf(type, Object::null_type_arguments(), | 1563 !const_value.IsInstanceOf(type, Object::null_type_arguments(), |
1553 &error))) { | 1564 Object::null_type_arguments(), &error))) { |
1554 if (Isolate::Current()->error_on_bad_type()) { | 1565 if (Isolate::Current()->error_on_bad_type()) { |
1555 const AbstractType& const_value_type = | 1566 const AbstractType& const_value_type = |
1556 AbstractType::Handle(zone, const_value.GetType(Heap::kNew)); | 1567 AbstractType::Handle(zone, const_value.GetType(Heap::kNew)); |
1557 const String& const_value_type_name = | 1568 const String& const_value_type_name = |
1558 String::Handle(zone, const_value_type.UserVisibleName()); | 1569 String::Handle(zone, const_value_type.UserVisibleName()); |
1559 const String& type_name = | 1570 const String& type_name = |
1560 String::Handle(zone, type.UserVisibleName()); | 1571 String::Handle(zone, type.UserVisibleName()); |
1561 ReportErrors(error, cls, field.token_pos(), | 1572 ReportErrors(error, cls, field.token_pos(), |
1562 "error initializing static %s field '%s': " | 1573 "error initializing static %s field '%s': " |
1563 "type '%s' is not a subtype of type '%s'", | 1574 "type '%s' is not a subtype of type '%s'", |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1870 for (intptr_t i = 0; i < num_mixin_type_params; i++) { | 1881 for (intptr_t i = 0; i < num_mixin_type_params; i++) { |
1871 param ^= mixin_type_args.TypeAt(i); | 1882 param ^= mixin_type_args.TypeAt(i); |
1872 param_bound = param.bound(); | 1883 param_bound = param.bound(); |
1873 if (!param_bound.IsInstantiated()) { | 1884 if (!param_bound.IsInstantiated()) { |
1874 // Make sure the bound is finalized before instantiating it. | 1885 // Make sure the bound is finalized before instantiating it. |
1875 if (!param_bound.IsFinalized() && !param_bound.IsBeingFinalized()) { | 1886 if (!param_bound.IsFinalized() && !param_bound.IsBeingFinalized()) { |
1876 param_bound = FinalizeType(mixin_app_class, param_bound); | 1887 param_bound = FinalizeType(mixin_app_class, param_bound); |
1877 param.set_bound(param_bound); // In case part of recursive type. | 1888 param.set_bound(param_bound); // In case part of recursive type. |
1878 } | 1889 } |
1879 param_bound = param_bound.InstantiateFrom( | 1890 param_bound = param_bound.InstantiateFrom( |
1880 instantiator, &bound_error, NULL, NULL, Heap::kOld); | 1891 instantiator, Object::null_type_arguments(), &bound_error, NULL, |
| 1892 NULL, Heap::kOld); |
1881 // The instantiator contains only TypeParameter objects and no | 1893 // The instantiator contains only TypeParameter objects and no |
1882 // BoundedType objects, so no bound error may occur. | 1894 // BoundedType objects, so no bound error may occur. |
1883 ASSERT(!param_bound.IsBoundedType()); | 1895 ASSERT(!param_bound.IsBoundedType()); |
1884 ASSERT(bound_error.IsNull()); | 1896 ASSERT(bound_error.IsNull()); |
1885 ASSERT(!param_bound.IsInstantiated()); | 1897 ASSERT(!param_bound.IsInstantiated()); |
1886 param.set_bound(param_bound); | 1898 param.set_bound(param_bound); |
1887 } | 1899 } |
1888 } | 1900 } |
1889 } | 1901 } |
1890 | 1902 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2105 mixin_class_super_type_args.Length() - num_aliased_mixin_type_params; | 2117 mixin_class_super_type_args.Length() - num_aliased_mixin_type_params; |
2106 for (intptr_t i = 0; i < num_aliased_mixin_type_params; i++) { | 2118 for (intptr_t i = 0; i < num_aliased_mixin_type_params; i++) { |
2107 type = mixin_class_super_type_args.TypeAt(offset + i); | 2119 type = mixin_class_super_type_args.TypeAt(offset + i); |
2108 if (!type.IsInstantiated()) { | 2120 if (!type.IsInstantiated()) { |
2109 // In the presence of bounds, the bounded type and the upper bound must | 2121 // In the presence of bounds, the bounded type and the upper bound must |
2110 // be instantiated separately. Instantiating a BoundedType would wrap | 2122 // be instantiated separately. Instantiating a BoundedType would wrap |
2111 // the BoundedType in another BoundedType. | 2123 // the BoundedType in another BoundedType. |
2112 if (type.IsBoundedType()) { | 2124 if (type.IsBoundedType()) { |
2113 bounded_type = BoundedType::Cast(type).type(); | 2125 bounded_type = BoundedType::Cast(type).type(); |
2114 bounded_type = bounded_type.InstantiateFrom( | 2126 bounded_type = bounded_type.InstantiateFrom( |
2115 instantiator, &bound_error, NULL, NULL, Heap::kOld); | 2127 instantiator, Object::null_type_arguments(), &bound_error, NULL, |
| 2128 NULL, Heap::kOld); |
2116 // The instantiator contains only TypeParameter objects and no | 2129 // The instantiator contains only TypeParameter objects and no |
2117 // BoundedType objects, so no bound error may occur. | 2130 // BoundedType objects, so no bound error may occur. |
2118 ASSERT(bound_error.IsNull()); | 2131 ASSERT(bound_error.IsNull()); |
2119 upper_bound = BoundedType::Cast(type).bound(); | 2132 upper_bound = BoundedType::Cast(type).bound(); |
2120 upper_bound = upper_bound.InstantiateFrom(instantiator, &bound_error, | 2133 upper_bound = upper_bound.InstantiateFrom( |
2121 NULL, NULL, Heap::kOld); | 2134 instantiator, Object::null_type_arguments(), &bound_error, NULL, |
| 2135 NULL, Heap::kOld); |
2122 ASSERT(bound_error.IsNull()); | 2136 ASSERT(bound_error.IsNull()); |
2123 type_parameter = BoundedType::Cast(type).type_parameter(); | 2137 type_parameter = BoundedType::Cast(type).type_parameter(); |
2124 // The type parameter that declared the bound does not change. | 2138 // The type parameter that declared the bound does not change. |
2125 type = BoundedType::New(bounded_type, upper_bound, type_parameter); | 2139 type = BoundedType::New(bounded_type, upper_bound, type_parameter); |
2126 } else { | 2140 } else { |
2127 type = type.InstantiateFrom(instantiator, &bound_error, NULL, NULL, | 2141 type = |
2128 Heap::kOld); | 2142 type.InstantiateFrom(instantiator, Object::null_type_arguments(), |
| 2143 &bound_error, NULL, NULL, Heap::kOld); |
2129 ASSERT(bound_error.IsNull()); | 2144 ASSERT(bound_error.IsNull()); |
2130 } | 2145 } |
2131 } | 2146 } |
2132 new_mixin_type_args.SetTypeAt(i, type); | 2147 new_mixin_type_args.SetTypeAt(i, type); |
2133 } | 2148 } |
2134 } | 2149 } |
2135 TypeArguments& new_super_type_args = TypeArguments::Handle(zone); | 2150 TypeArguments& new_super_type_args = TypeArguments::Handle(zone); |
2136 if ((num_super_type_params + num_aliased_mixin_type_params) > 0) { | 2151 if ((num_super_type_params + num_aliased_mixin_type_params) > 0) { |
2137 new_super_type_args = TypeArguments::New(num_super_type_params + | 2152 new_super_type_args = TypeArguments::New(num_super_type_params + |
2138 num_aliased_mixin_type_params); | 2153 num_aliased_mixin_type_params); |
(...skipping 1609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3748 ProgramVisitor::VisitFunctions(&function_visitor); | 3763 ProgramVisitor::VisitFunctions(&function_visitor); |
3749 | 3764 |
3750 class ClearCodeClassVisitor : public ClassVisitor { | 3765 class ClearCodeClassVisitor : public ClassVisitor { |
3751 void Visit(const Class& cls) { cls.DisableAllocationStub(); } | 3766 void Visit(const Class& cls) { cls.DisableAllocationStub(); } |
3752 }; | 3767 }; |
3753 ClearCodeClassVisitor class_visitor; | 3768 ClearCodeClassVisitor class_visitor; |
3754 ProgramVisitor::VisitClasses(&class_visitor); | 3769 ProgramVisitor::VisitClasses(&class_visitor); |
3755 } | 3770 } |
3756 | 3771 |
3757 } // namespace dart | 3772 } // namespace dart |
OLD | NEW |