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

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

Issue 113163008: Add missing ResolveType call (fix issue 15738). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/class_finalizer.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 if (!target.IsNull()) { 313 if (!target.IsNull()) {
314 // Already resolved. 314 // Already resolved.
315 return; 315 return;
316 } 316 }
317 317
318 // Target is not resolved yet. 318 // Target is not resolved yet.
319 if (FLAG_trace_class_finalization) { 319 if (FLAG_trace_class_finalization) {
320 OS::Print("Resolving redirecting factory: %s\n", 320 OS::Print("Resolving redirecting factory: %s\n",
321 String::Handle(factory.name()).ToCString()); 321 String::Handle(factory.name()).ToCString());
322 } 322 }
323 ResolveType(cls, type, kCanonicalize); 323 ResolveType(cls, type);
324 type ^= FinalizeType(cls, type, kCanonicalize); 324 type ^= FinalizeType(cls, type, kCanonicalize);
325 factory.SetRedirectionType(type); 325 factory.SetRedirectionType(type);
326 if (type.IsMalformedOrMalbounded()) { 326 if (type.IsMalformedOrMalbounded()) {
327 ASSERT(factory.RedirectionTarget() == Function::null()); 327 ASSERT(factory.RedirectionTarget() == Function::null());
328 return; 328 return;
329 } 329 }
330 ASSERT(!type.IsTypeParameter()); // Resolved in parser. 330 ASSERT(!type.IsTypeParameter()); // Resolved in parser.
331 if (type.IsDynamicType()) { 331 if (type.IsDynamicType()) {
332 // Replace the type with a malformed type and compile a throw when called. 332 // Replace the type with a malformed type and compile a throw when called.
333 type = NewFinalizedMalformedType( 333 type = NewFinalizedMalformedType(
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 "cannot resolve redirecting factory"); 430 "cannot resolve redirecting factory");
431 target_target = Function::null(); 431 target_target = Function::null();
432 } 432 }
433 } 433 }
434 } 434 }
435 factory.SetRedirectionType(target_type); 435 factory.SetRedirectionType(target_type);
436 factory.SetRedirectionTarget(target_target); 436 factory.SetRedirectionTarget(target_target);
437 } 437 }
438 438
439 439
440 void ClassFinalizer::ResolveType(const Class& cls, 440 void ClassFinalizer::ResolveType(const Class& cls, const AbstractType& type) {
441 const AbstractType& type,
442 FinalizationKind finalization) {
443 if (type.IsResolved() || type.IsFinalized()) { 441 if (type.IsResolved() || type.IsFinalized()) {
444 return; 442 return;
445 } 443 }
446 if (FLAG_trace_type_finalization) { 444 if (FLAG_trace_type_finalization) {
447 OS::Print("Resolve type '%s'\n", String::Handle(type.Name()).ToCString()); 445 OS::Print("Resolve type '%s'\n", String::Handle(type.Name()).ToCString());
448 } 446 }
449 447
450 // Resolve the type class. 448 // Resolve the type class.
451 if (!type.HasResolvedTypeClass()) { 449 if (!type.HasResolvedTypeClass()) {
452 // Type parameters are always resolved in the parser in the correct 450 // Type parameters are always resolved in the parser in the correct
(...skipping 25 matching lines...) Expand all
478 } 476 }
479 477
480 // Resolve type arguments, if any. 478 // Resolve type arguments, if any.
481 const AbstractTypeArguments& arguments = 479 const AbstractTypeArguments& arguments =
482 AbstractTypeArguments::Handle(type.arguments()); 480 AbstractTypeArguments::Handle(type.arguments());
483 if (!arguments.IsNull()) { 481 if (!arguments.IsNull()) {
484 const intptr_t num_arguments = arguments.Length(); 482 const intptr_t num_arguments = arguments.Length();
485 AbstractType& type_argument = AbstractType::Handle(); 483 AbstractType& type_argument = AbstractType::Handle();
486 for (intptr_t i = 0; i < num_arguments; i++) { 484 for (intptr_t i = 0; i < num_arguments; i++) {
487 type_argument = arguments.TypeAt(i); 485 type_argument = arguments.TypeAt(i);
488 ResolveType(cls, type_argument, finalization); 486 ResolveType(cls, type_argument);
489 } 487 }
490 } 488 }
491 } 489 }
492 490
493 491
494 void ClassFinalizer::FinalizeTypeParameters( 492 void ClassFinalizer::FinalizeTypeParameters(
495 const Class& cls, 493 const Class& cls,
496 GrowableObjectArray* pending_types) { 494 GrowableObjectArray* pending_types) {
497 if (cls.IsMixinApplication()) { 495 if (cls.IsMixinApplication()) {
498 // Setup the type parameters of the mixin application and finalize the 496 // Setup the type parameters of the mixin application and finalize the
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 } 984 }
987 } 985 }
988 986
989 987
990 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls, 988 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls,
991 const Function& function) { 989 const Function& function) {
992 // Resolve result type. 990 // Resolve result type.
993 AbstractType& type = AbstractType::Handle(function.result_type()); 991 AbstractType& type = AbstractType::Handle(function.result_type());
994 // It is not a compile time error if this name does not resolve to a class or 992 // It is not a compile time error if this name does not resolve to a class or
995 // interface. 993 // interface.
996 ResolveType(cls, type, kCanonicalize); 994 ResolveType(cls, type);
997 type = FinalizeType(cls, type, kCanonicalize); 995 type = FinalizeType(cls, type, kCanonicalize);
998 // The result type may be malformed or malbounded. 996 // The result type may be malformed or malbounded.
999 function.set_result_type(type); 997 function.set_result_type(type);
1000 // Resolve formal parameter types. 998 // Resolve formal parameter types.
1001 const intptr_t num_parameters = function.NumParameters(); 999 const intptr_t num_parameters = function.NumParameters();
1002 for (intptr_t i = 0; i < num_parameters; i++) { 1000 for (intptr_t i = 0; i < num_parameters; i++) {
1003 type = function.ParameterTypeAt(i); 1001 type = function.ParameterTypeAt(i);
1004 ResolveType(cls, type, kCanonicalize); 1002 ResolveType(cls, type);
1005 type = FinalizeType(cls, type, kCanonicalize); 1003 type = FinalizeType(cls, type, kCanonicalize);
1006 // The parameter type may be malformed or malbounded. 1004 // The parameter type may be malformed or malbounded.
1007 function.SetParameterTypeAt(i, type); 1005 function.SetParameterTypeAt(i, type);
1008 } 1006 }
1009 } 1007 }
1010 1008
1011 1009
1012 // Check if an instance field, getter, or method of same name exists 1010 // Check if an instance field, getter, or method of same name exists
1013 // in any super class. 1011 // in any super class.
1014 static RawClass* FindSuperOwnerOfInstanceMember(const Class& cls, 1012 static RawClass* FindSuperOwnerOfInstanceMember(const Class& cls,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 AbstractType& bound = AbstractType::Handle(); 1061 AbstractType& bound = AbstractType::Handle();
1064 const AbstractTypeArguments& type_params = 1062 const AbstractTypeArguments& type_params =
1065 AbstractTypeArguments::Handle(cls.type_parameters()); 1063 AbstractTypeArguments::Handle(cls.type_parameters());
1066 ASSERT((type_params.IsNull() && (num_type_params == 0)) || 1064 ASSERT((type_params.IsNull() && (num_type_params == 0)) ||
1067 (type_params.Length() == num_type_params)); 1065 (type_params.Length() == num_type_params));
1068 // In a first pass, resolve all bounds. This guarantees that finalization 1066 // In a first pass, resolve all bounds. This guarantees that finalization
1069 // of mutually referencing bounds will not encounter an unresolved bound. 1067 // of mutually referencing bounds will not encounter an unresolved bound.
1070 for (intptr_t i = 0; i < num_type_params; i++) { 1068 for (intptr_t i = 0; i < num_type_params; i++) {
1071 type_param ^= type_params.TypeAt(i); 1069 type_param ^= type_params.TypeAt(i);
1072 bound = type_param.bound(); 1070 bound = type_param.bound();
1073 ResolveType(cls, bound, kCanonicalize); 1071 ResolveType(cls, bound);
1074 } 1072 }
1075 } 1073 }
1076 1074
1077 1075
1078 // Finalize the upper bounds of the type parameters of class cls. 1076 // Finalize the upper bounds of the type parameters of class cls.
1079 void ClassFinalizer::FinalizeUpperBounds(const Class& cls) { 1077 void ClassFinalizer::FinalizeUpperBounds(const Class& cls) {
1080 const intptr_t num_type_params = cls.NumTypeParameters(); 1078 const intptr_t num_type_params = cls.NumTypeParameters();
1081 TypeParameter& type_param = TypeParameter::Handle(); 1079 TypeParameter& type_param = TypeParameter::Handle();
1082 AbstractType& bound = AbstractType::Handle(); 1080 AbstractType& bound = AbstractType::Handle();
1083 const AbstractTypeArguments& type_params = 1081 const AbstractTypeArguments& type_params =
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 Field& field = Field::Handle(); 1121 Field& field = Field::Handle();
1124 AbstractType& type = AbstractType::Handle(); 1122 AbstractType& type = AbstractType::Handle();
1125 String& name = String::Handle(); 1123 String& name = String::Handle();
1126 String& getter_name = String::Handle(); 1124 String& getter_name = String::Handle();
1127 String& setter_name = String::Handle(); 1125 String& setter_name = String::Handle();
1128 Class& super_class = Class::Handle(); 1126 Class& super_class = Class::Handle();
1129 const intptr_t num_fields = array.Length(); 1127 const intptr_t num_fields = array.Length();
1130 for (intptr_t i = 0; i < num_fields; i++) { 1128 for (intptr_t i = 0; i < num_fields; i++) {
1131 field ^= array.At(i); 1129 field ^= array.At(i);
1132 type = field.type(); 1130 type = field.type();
1133 ResolveType(cls, type, kCanonicalize); 1131 ResolveType(cls, type);
1134 type = FinalizeType(cls, type, kCanonicalize); 1132 type = FinalizeType(cls, type, kCanonicalize);
1135 field.set_type(type); 1133 field.set_type(type);
1136 name = field.name(); 1134 name = field.name();
1137 if (field.is_static()) { 1135 if (field.is_static()) {
1138 getter_name = Field::GetterSymbol(name); 1136 getter_name = Field::GetterSymbol(name);
1139 super_class = FindSuperOwnerOfInstanceMember(cls, name, getter_name); 1137 super_class = FindSuperOwnerOfInstanceMember(cls, name, getter_name);
1140 if (!super_class.IsNull()) { 1138 if (!super_class.IsNull()) {
1141 const String& class_name = String::Handle(cls.Name()); 1139 const String& class_name = String::Handle(cls.Name());
1142 const String& super_class_name = String::Handle(super_class.Name()); 1140 const String& super_class_name = String::Handle(super_class.Name());
1143 const Script& script = Script::Handle(cls.script()); 1141 const Script& script = Script::Handle(cls.script());
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 return true; 2147 return true;
2150 } 2148 }
2151 2149
2152 2150
2153 // Helper function called by IsAliasCycleFree. 2151 // Helper function called by IsAliasCycleFree.
2154 bool ClassFinalizer::IsTypeCycleFree( 2152 bool ClassFinalizer::IsTypeCycleFree(
2155 const Class& cls, 2153 const Class& cls,
2156 const AbstractType& type, 2154 const AbstractType& type,
2157 GrowableArray<intptr_t>* visited) { 2155 GrowableArray<intptr_t>* visited) {
2158 ASSERT(visited != NULL); 2156 ASSERT(visited != NULL);
2159 ResolveType(cls, type, kCanonicalize); 2157 ResolveType(cls, type);
2160 if (type.IsType() && !type.IsMalformed()) { 2158 if (type.IsType() && !type.IsMalformed()) {
2161 const Class& type_class = Class::Handle(type.type_class()); 2159 const Class& type_class = Class::Handle(type.type_class());
2162 if (!type_class.is_type_finalized() && 2160 if (!type_class.is_type_finalized() &&
2163 type_class.IsSignatureClass() && 2161 type_class.IsSignatureClass() &&
2164 !IsAliasCycleFree(type_class, visited)) { 2162 !IsAliasCycleFree(type_class, visited)) {
2165 return false; 2163 return false;
2166 } 2164 }
2167 const AbstractTypeArguments& type_args = AbstractTypeArguments::Handle( 2165 const AbstractTypeArguments& type_args = AbstractTypeArguments::Handle(
2168 type.arguments()); 2166 type.arguments());
2169 if (!type_args.IsNull()) { 2167 if (!type_args.IsNull()) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 // Lookup or create mixin application classes in the library of cls 2307 // Lookup or create mixin application classes in the library of cls
2310 // and resolve super type and mixin types. 2308 // and resolve super type and mixin types.
2311 const Library& library = Library::Handle(cls.library()); 2309 const Library& library = Library::Handle(cls.library());
2312 ASSERT(!library.IsNull()); 2310 ASSERT(!library.IsNull());
2313 const Script& script = Script::Handle(cls.script()); 2311 const Script& script = Script::Handle(cls.script());
2314 ASSERT(!script.IsNull()); 2312 ASSERT(!script.IsNull());
2315 const GrowableObjectArray& type_args = 2313 const GrowableObjectArray& type_args =
2316 GrowableObjectArray::Handle(GrowableObjectArray::New()); 2314 GrowableObjectArray::Handle(GrowableObjectArray::New());
2317 AbstractType& mixin_super_type = 2315 AbstractType& mixin_super_type =
2318 AbstractType::Handle(mixin_app_type.super_type()); 2316 AbstractType::Handle(mixin_app_type.super_type());
2319 ResolveType(cls, mixin_super_type, kCanonicalizeWellFormed); 2317 ResolveType(cls, mixin_super_type);
2320 ASSERT(mixin_super_type.HasResolvedTypeClass()); 2318 ASSERT(mixin_super_type.HasResolvedTypeClass());
2321 // TODO(14453): May need to handle BoundedType here. 2319 // TODO(14453): May need to handle BoundedType here.
2322 ASSERT(mixin_super_type.IsType()); 2320 ASSERT(mixin_super_type.IsType());
2323 CollectTypeArguments(cls, Type::Cast(mixin_super_type), type_args); 2321 CollectTypeArguments(cls, Type::Cast(mixin_super_type), type_args);
2324 AbstractType& mixin_type = AbstractType::Handle(); 2322 AbstractType& mixin_type = AbstractType::Handle();
2325 Type& generic_mixin_type = Type::Handle(); 2323 Type& generic_mixin_type = Type::Handle();
2326 Class& mixin_type_class = Class::Handle(); 2324 Class& mixin_type_class = Class::Handle();
2327 Class& mixin_app_class = Class::Handle(); 2325 Class& mixin_app_class = Class::Handle();
2328 String& mixin_app_class_name = String::Handle(); 2326 String& mixin_app_class_name = String::Handle();
2329 String& mixin_type_class_name = String::Handle(); 2327 String& mixin_type_class_name = String::Handle();
2330 const intptr_t depth = mixin_app_type.Depth(); 2328 const intptr_t depth = mixin_app_type.Depth();
2331 for (intptr_t i = 0; i < depth; i++) { 2329 for (intptr_t i = 0; i < depth; i++) {
2332 mixin_type = mixin_app_type.MixinTypeAt(i); 2330 mixin_type = mixin_app_type.MixinTypeAt(i);
2333 ASSERT(!mixin_type.IsNull()); 2331 ASSERT(!mixin_type.IsNull());
2334 ResolveType(cls, mixin_type, kCanonicalizeWellFormed); 2332 ResolveType(cls, mixin_type);
2335 ASSERT(mixin_type.HasResolvedTypeClass()); 2333 ASSERT(mixin_type.HasResolvedTypeClass());
2336 ASSERT(mixin_type.IsType()); 2334 ASSERT(mixin_type.IsType());
2337 CollectTypeArguments(cls, Type::Cast(mixin_type), type_args); 2335 CollectTypeArguments(cls, Type::Cast(mixin_type), type_args);
2338 2336
2339 // The name of the mixin application class is a combination of 2337 // The name of the mixin application class is a combination of
2340 // the super class name and mixin class name. 2338 // the super class name and mixin class name.
2341 mixin_app_class_name = mixin_super_type.ClassName(); 2339 mixin_app_class_name = mixin_super_type.ClassName();
2342 mixin_app_class_name = String::Concat(mixin_app_class_name, 2340 mixin_app_class_name = String::Concat(mixin_app_class_name,
2343 Symbols::Ampersand()); 2341 Symbols::Ampersand());
2344 mixin_type_class_name = mixin_type.ClassName(); 2342 mixin_type_class_name = mixin_type.ClassName();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2439 // If cls belongs to core lib, restrictions about allowed interfaces 2437 // If cls belongs to core lib, restrictions about allowed interfaces
2440 // are lifted. 2438 // are lifted.
2441 const bool cls_belongs_to_core_lib = cls.library() == Library::CoreLibrary(); 2439 const bool cls_belongs_to_core_lib = cls.library() == Library::CoreLibrary();
2442 2440
2443 // Resolve and check the super type and interfaces of cls. 2441 // Resolve and check the super type and interfaces of cls.
2444 visited->Add(cls_index); 2442 visited->Add(cls_index);
2445 AbstractType& interface = AbstractType::Handle(); 2443 AbstractType& interface = AbstractType::Handle();
2446 Class& interface_class = Class::Handle(); 2444 Class& interface_class = Class::Handle();
2447 2445
2448 // Resolve super type. Failures lead to a longjmp. 2446 // Resolve super type. Failures lead to a longjmp.
2449 ResolveType(cls, super_type, kCanonicalizeWellFormed); 2447 ResolveType(cls, super_type);
2450 if (super_type.IsMalformedOrMalbounded()) { 2448 if (super_type.IsMalformedOrMalbounded()) {
2451 ReportError(Error::Handle(super_type.error())); 2449 ReportError(Error::Handle(super_type.error()));
2452 } 2450 }
2453 if (super_type.IsDynamicType()) { 2451 if (super_type.IsDynamicType()) {
2454 const Script& script = Script::Handle(cls.script()); 2452 const Script& script = Script::Handle(cls.script());
2455 ReportError(Error::Handle(), // No previous error. 2453 ReportError(Error::Handle(), // No previous error.
2456 script, cls.token_pos(), 2454 script, cls.token_pos(),
2457 "class '%s' may not extend 'dynamic'", 2455 "class '%s' may not extend 'dynamic'",
2458 String::Handle(cls.Name()).ToCString()); 2456 String::Handle(cls.Name()).ToCString());
2459 } 2457 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2516 String::Handle(cls.Name()).ToCString(), 2514 String::Handle(cls.Name()).ToCString(),
2517 String::Handle(interface_class.Name()).ToCString()); 2515 String::Handle(interface_class.Name()).ToCString());
2518 } 2516 }
2519 } 2517 }
2520 // Now resolve the super interfaces of the super type. 2518 // Now resolve the super interfaces of the super type.
2521 ResolveSuperTypeAndInterfaces(interface_class, visited); 2519 ResolveSuperTypeAndInterfaces(interface_class, visited);
2522 2520
2523 // Resolve interfaces. Failures lead to a longjmp. 2521 // Resolve interfaces. Failures lead to a longjmp.
2524 for (intptr_t i = 0; i < super_interfaces.Length(); i++) { 2522 for (intptr_t i = 0; i < super_interfaces.Length(); i++) {
2525 interface ^= super_interfaces.At(i); 2523 interface ^= super_interfaces.At(i);
2526 ResolveType(cls, interface, kCanonicalizeWellFormed); 2524 ResolveType(cls, interface);
2527 ASSERT(!interface.IsTypeParameter()); // Should be detected by parser. 2525 ASSERT(!interface.IsTypeParameter()); // Should be detected by parser.
2528 // A malbounded interface is only reported when involved in a type test. 2526 // A malbounded interface is only reported when involved in a type test.
2529 if (interface.IsMalformed()) { 2527 if (interface.IsMalformed()) {
2530 ReportError(Error::Handle(interface.error())); 2528 ReportError(Error::Handle(interface.error()));
2531 } 2529 }
2532 if (interface.IsDynamicType()) { 2530 if (interface.IsDynamicType()) {
2533 const Script& script = Script::Handle(cls.script()); 2531 const Script& script = Script::Handle(cls.script());
2534 ReportError(Error::Handle(), // No previous error. 2532 ReportError(Error::Handle(), // No previous error.
2535 script, cls.token_pos(), 2533 script, cls.token_pos(),
2536 "'dynamic' may not be used as interface"); 2534 "'dynamic' may not be used as interface");
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
2805 expected_name ^= String::New("_offset"); 2803 expected_name ^= String::New("_offset");
2806 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); 2804 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name));
2807 field ^= fields_array.At(2); 2805 field ^= fields_array.At(2);
2808 ASSERT(field.Offset() == TypedDataView::length_offset()); 2806 ASSERT(field.Offset() == TypedDataView::length_offset());
2809 name ^= field.name(); 2807 name ^= field.name();
2810 ASSERT(name.Equals("length")); 2808 ASSERT(name.Equals("length"));
2811 #endif 2809 #endif
2812 } 2810 }
2813 2811
2814 } // namespace dart 2812 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698