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

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

Issue 2592263004: Fix resolution and canonicalization of typedefs and function types in (Closed)
Patch Set: address comments and todos Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/isolate_reload.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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 const intptr_t num_arguments = arguments.Length(); 542 const intptr_t num_arguments = arguments.Length();
543 AbstractType& type_argument = AbstractType::Handle(); 543 AbstractType& type_argument = AbstractType::Handle();
544 for (intptr_t i = 0; i < num_arguments; i++) { 544 for (intptr_t i = 0; i < num_arguments; i++) {
545 type_argument = arguments.TypeAt(i); 545 type_argument = arguments.TypeAt(i);
546 ResolveType(cls, type_argument); 546 ResolveType(cls, type_argument);
547 } 547 }
548 } 548 }
549 // Resolve signature if function type. 549 // Resolve signature if function type.
550 if (type.IsFunctionType()) { 550 if (type.IsFunctionType()) {
551 const Function& signature = Function::Handle(Type::Cast(type).signature()); 551 const Function& signature = Function::Handle(Type::Cast(type).signature());
552 const Class& scope_class = Class::Handle(type.type_class()); 552 Type& signature_type = Type::Handle(signature.SignatureType());
553 if (scope_class.IsTypedefClass()) { 553 if (signature_type.raw() != type.raw()) {
554 ResolveSignature(scope_class, signature); 554 ResolveType(cls, signature_type);
555 } else { 555 } else {
556 ResolveSignature(cls, signature); 556 const Class& scope_class = Class::Handle(type.type_class());
557 if (scope_class.IsTypedefClass()) {
558 ResolveSignature(scope_class, signature);
559 } else {
560 ResolveSignature(cls, signature);
561 }
562 if (signature.IsSignatureFunction()) {
563 // Drop fields that are not necessary anymore after resolution.
564 // The parent function, owner, and token position of a shared
565 // canonical function type are meaningless, since the canonical
566 // representent is picked arbitrarily.
567 signature.set_parent_function(Function::Handle());
568 // TODO(regis): As long as we support metadata in typedef signatures,
569 // we cannot reset these fields used to reparse a typedef.
570 // Note that the scope class of a typedef function type is always
571 // preserved as the typedef class (not reset to _Closure class), thereby
572 // preventing sharing of canonical function types between typedefs.
573 // Not being shared, these fields are therefore always meaningful for
574 // typedefs.
575 if (!scope_class.IsTypedefClass()) {
576 signature.set_owner(Object::Handle());
577 signature.set_token_pos(TokenPosition::kNoSource);
578 }
579 }
557 } 580 }
558 } 581 }
559 } 582 }
560 583
561 584
562 void ClassFinalizer::FinalizeTypeParameters(const Class& cls, 585 void ClassFinalizer::FinalizeTypeParameters(const Class& cls,
563 PendingTypes* pending_types) { 586 PendingTypes* pending_types) {
564 if (FLAG_trace_type_finalization) { 587 if (FLAG_trace_type_finalization) {
565 THR_Print("Finalizing type parameters of '%s'\n", 588 THR_Print("Finalizing type parameters of '%s'\n",
566 String::Handle(cls.Name()).ToCString()); 589 String::Handle(cls.Name()).ToCString());
(...skipping 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after
2324 super_type = FinalizeType(cls, super_type, kCanonicalizeWellFormed); 2347 super_type = FinalizeType(cls, super_type, kCanonicalizeWellFormed);
2325 cls.set_super_type(super_type); 2348 cls.set_super_type(super_type);
2326 } 2349 }
2327 // Finalize mixin type. 2350 // Finalize mixin type.
2328 Type& mixin_type = Type::Handle(cls.mixin()); 2351 Type& mixin_type = Type::Handle(cls.mixin());
2329 if (!mixin_type.IsNull()) { 2352 if (!mixin_type.IsNull()) {
2330 mixin_type ^= FinalizeType(cls, mixin_type, kCanonicalizeWellFormed); 2353 mixin_type ^= FinalizeType(cls, mixin_type, kCanonicalizeWellFormed);
2331 cls.set_mixin(mixin_type); 2354 cls.set_mixin(mixin_type);
2332 } 2355 }
2333 if (cls.IsTypedefClass()) { 2356 if (cls.IsTypedefClass()) {
2334 const Function& signature = Function::Handle(cls.signature_function()); 2357 Function& signature = Function::Handle(cls.signature_function());
2335 Type& type = Type::Handle(signature.SignatureType()); 2358 Type& type = Type::Handle(signature.SignatureType());
2359 ASSERT(type.signature() == signature.raw());
2336 2360
2337 // Check for illegal self references. 2361 // Check for illegal self references.
2338 GrowableArray<intptr_t> visited_aliases; 2362 GrowableArray<intptr_t> visited_aliases;
2339 if (!IsTypedefCycleFree(cls, type, &visited_aliases)) { 2363 if (!IsTypedefCycleFree(cls, type, &visited_aliases)) {
2340 const String& name = String::Handle(cls.Name()); 2364 const String& name = String::Handle(cls.Name());
2341 ReportError(cls, cls.token_pos(), 2365 ReportError(cls, cls.token_pos(),
2342 "typedef '%s' illegally refers to itself", name.ToCString()); 2366 "typedef '%s' illegally refers to itself", name.ToCString());
2343 } 2367 }
2344 cls.set_is_type_finalized(); 2368 cls.set_is_type_finalized();
2345 2369
2346 // Resolve and finalize the result and parameter types of the signature 2370 // Resolve and finalize the result and parameter types of the signature
2347 // function of this typedef class. 2371 // function of this typedef class.
2348 FinalizeSignature(cls, signature); // Does not modify signature type. 2372 FinalizeSignature(cls, signature); // Does not modify signature type.
2349 ASSERT(signature.SignatureType() == type.raw()); 2373 ASSERT(signature.SignatureType() == type.raw());
2350 2374
2351 // Resolve and finalize the signature type of this typedef. 2375 // Resolve and finalize the signature type of this typedef.
2352 type ^= FinalizeType(cls, type, kCanonicalizeWellFormed); 2376 type ^= FinalizeType(cls, type, kCanonicalizeWellFormed);
2377
2378 // If a different canonical signature type is returned, update the signature
2379 // function of the typedef.
2380 signature = type.signature();
2353 signature.SetSignatureType(type); 2381 signature.SetSignatureType(type);
2382 cls.set_signature_function(signature);
2354 2383
2355 // Closure instances do not refer to this typedef as their class, so there 2384 // Closure instances do not refer to this typedef as their class, so there
2356 // is no need to add this typedef class to the subclasses of _Closure. 2385 // is no need to add this typedef class to the subclasses of _Closure.
2357 ASSERT(super_type.IsNull() || super_type.IsObjectType()); 2386 ASSERT(super_type.IsNull() || super_type.IsObjectType());
2358 2387
2359 return; 2388 return;
2360 } 2389 }
2361 2390
2362 // Finalize interface types (but not necessarily interface classes). 2391 // Finalize interface types (but not necessarily interface classes).
2363 Array& interface_types = Array::Handle(cls.interfaces()); 2392 Array& interface_types = Array::Handle(cls.interfaces());
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after
3350 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); 3379 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields());
3351 field ^= fields_array.At(0); 3380 field ^= fields_array.At(0);
3352 ASSERT(field.Offset() == ByteBuffer::data_offset()); 3381 ASSERT(field.Offset() == ByteBuffer::data_offset());
3353 name ^= field.name(); 3382 name ^= field.name();
3354 expected_name ^= String::New("_data"); 3383 expected_name ^= String::New("_data");
3355 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); 3384 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name));
3356 #endif 3385 #endif
3357 } 3386 }
3358 3387
3359 } // namespace dart 3388 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/isolate_reload.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698