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/heap.h" | 9 #include "vm/heap.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
(...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 const intptr_t num_type_params = cls.NumTypeParameters(); | 1262 const intptr_t num_type_params = cls.NumTypeParameters(); |
1263 TypeParameter& type_param = TypeParameter::Handle(); | 1263 TypeParameter& type_param = TypeParameter::Handle(); |
1264 AbstractType& bound = AbstractType::Handle(); | 1264 AbstractType& bound = AbstractType::Handle(); |
1265 const TypeArguments& type_params = | 1265 const TypeArguments& type_params = |
1266 TypeArguments::Handle(cls.type_parameters()); | 1266 TypeArguments::Handle(cls.type_parameters()); |
1267 ASSERT((type_params.IsNull() && (num_type_params == 0)) || | 1267 ASSERT((type_params.IsNull() && (num_type_params == 0)) || |
1268 (type_params.Length() == num_type_params)); | 1268 (type_params.Length() == num_type_params)); |
1269 for (intptr_t i = 0; i < num_type_params; i++) { | 1269 for (intptr_t i = 0; i < num_type_params; i++) { |
1270 type_param ^= type_params.TypeAt(i); | 1270 type_param ^= type_params.TypeAt(i); |
1271 bound = type_param.bound(); | 1271 bound = type_param.bound(); |
1272 if (bound.IsFinalized() || bound.IsBeingFinalized()) { | 1272 // Bound may be finalized, but not canonical yet. |
| 1273 if (bound.IsCanonical() || bound.IsBeingFinalized()) { |
1273 // A bound involved in F-bounded quantification may form a cycle. | 1274 // A bound involved in F-bounded quantification may form a cycle. |
1274 continue; | 1275 continue; |
1275 } | 1276 } |
1276 bound = FinalizeType(cls, bound, kCanonicalize); | 1277 bound = FinalizeType(cls, bound, kCanonicalize); |
1277 type_param.set_bound(bound); | 1278 type_param.set_bound(bound); |
1278 } | 1279 } |
1279 } | 1280 } |
1280 | 1281 |
1281 | 1282 |
1282 void ClassFinalizer::ResolveAndFinalizeMemberTypes(const Class& cls) { | 1283 void ClassFinalizer::ResolveAndFinalizeMemberTypes(const Class& cls) { |
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2224 } | 2225 } |
2225 // Finalize super class. | 2226 // Finalize super class. |
2226 Class& super_class = Class::Handle(cls.SuperClass()); | 2227 Class& super_class = Class::Handle(cls.SuperClass()); |
2227 if (!super_class.IsNull()) { | 2228 if (!super_class.IsNull()) { |
2228 FinalizeTypesInClass(super_class); | 2229 FinalizeTypesInClass(super_class); |
2229 } | 2230 } |
2230 // Finalize type parameters before finalizing the super type. | 2231 // Finalize type parameters before finalizing the super type. |
2231 FinalizeTypeParameters(cls); // May change super type. | 2232 FinalizeTypeParameters(cls); // May change super type. |
2232 super_class = cls.SuperClass(); | 2233 super_class = cls.SuperClass(); |
2233 ASSERT(super_class.IsNull() || super_class.is_type_finalized()); | 2234 ASSERT(super_class.IsNull() || super_class.is_type_finalized()); |
2234 ResolveUpperBounds(cls); | 2235 // Only resolving rather than finalizing the upper bounds here would result in |
| 2236 // instantiated type parameters of the super type to temporarily have |
| 2237 // unfinalized bounds. It is more efficient to finalize them early. |
| 2238 FinalizeUpperBounds(cls); |
2235 // Finalize super type. | 2239 // Finalize super type. |
2236 AbstractType& super_type = AbstractType::Handle(cls.super_type()); | 2240 AbstractType& super_type = AbstractType::Handle(cls.super_type()); |
2237 if (!super_type.IsNull()) { | 2241 if (!super_type.IsNull()) { |
2238 // In case of a bound error in the super type in production mode, the | 2242 // In case of a bound error in the super type in production mode, the |
2239 // finalized super type will have a BoundedType as type argument for the | 2243 // finalized super type will have a BoundedType as type argument for the |
2240 // out of bound type argument. | 2244 // out of bound type argument. |
2241 // It should not be a problem if the class is written to a snapshot and | 2245 // It should not be a problem if the class is written to a snapshot and |
2242 // later executed in checked mode. Note that the finalized type argument | 2246 // later executed in checked mode. Note that the finalized type argument |
2243 // vector of any type of the base class will contain a BoundedType for the | 2247 // vector of any type of the base class will contain a BoundedType for the |
2244 // out of bound type argument. | 2248 // out of bound type argument. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2337 // 'ResolveAndFinalizeMemberTypes(cls)' has not been called yet, unfinalized | 2341 // 'ResolveAndFinalizeMemberTypes(cls)' has not been called yet, unfinalized |
2338 // member types could choke the snapshotter. | 2342 // member types could choke the snapshotter. |
2339 ASSERT(Array::Handle(cls.functions()).Length() == 0); | 2343 ASSERT(Array::Handle(cls.functions()).Length() == 0); |
2340 } | 2344 } |
2341 } | 2345 } |
2342 | 2346 |
2343 | 2347 |
2344 void ClassFinalizer::FinalizeClass(const Class& cls) { | 2348 void ClassFinalizer::FinalizeClass(const Class& cls) { |
2345 Thread* thread = Thread::Current(); | 2349 Thread* thread = Thread::Current(); |
2346 HANDLESCOPE(thread); | 2350 HANDLESCOPE(thread); |
| 2351 ASSERT(cls.is_type_finalized()); |
2347 if (cls.is_finalized()) { | 2352 if (cls.is_finalized()) { |
2348 return; | 2353 return; |
2349 } | 2354 } |
2350 if (FLAG_trace_class_finalization) { | 2355 if (FLAG_trace_class_finalization) { |
2351 THR_Print("Finalize %s\n", cls.ToCString()); | 2356 THR_Print("Finalize %s\n", cls.ToCString()); |
2352 } | 2357 } |
2353 if (cls.is_patch()) { | 2358 if (cls.is_patch()) { |
2354 // The fields and functions of a patch class are copied to the | 2359 // The fields and functions of a patch class are copied to the |
2355 // patched class after parsing. There is nothing to finalize. | 2360 // patched class after parsing. There is nothing to finalize. |
2356 ASSERT(Array::Handle(cls.functions()).Length() == 0); | 2361 ASSERT(Array::Handle(cls.functions()).Length() == 0); |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3203 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); | 3208 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); |
3204 field ^= fields_array.At(0); | 3209 field ^= fields_array.At(0); |
3205 ASSERT(field.Offset() == ByteBuffer::data_offset()); | 3210 ASSERT(field.Offset() == ByteBuffer::data_offset()); |
3206 name ^= field.name(); | 3211 name ^= field.name(); |
3207 expected_name ^= String::New("_data"); | 3212 expected_name ^= String::New("_data"); |
3208 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 3213 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
3209 #endif | 3214 #endif |
3210 } | 3215 } |
3211 | 3216 |
3212 } // namespace dart | 3217 } // namespace dart |
OLD | NEW |