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

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

Issue 19260003: Allow the optimizer to canonicalize instantiated function types (issue 11775). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | 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) 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 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 1437
1438 RawType* Class::SignatureType() const { 1438 RawType* Class::SignatureType() const {
1439 ASSERT(IsSignatureClass()); 1439 ASSERT(IsSignatureClass());
1440 const Function& function = Function::Handle(signature_function()); 1440 const Function& function = Function::Handle(signature_function());
1441 ASSERT(!function.IsNull()); 1441 ASSERT(!function.IsNull());
1442 if (function.signature_class() != raw()) { 1442 if (function.signature_class() != raw()) {
1443 // This class is a function type alias. Return the canonical signature type. 1443 // This class is a function type alias. Return the canonical signature type.
1444 const Class& canonical_class = Class::Handle(function.signature_class()); 1444 const Class& canonical_class = Class::Handle(function.signature_class());
1445 return canonical_class.SignatureType(); 1445 return canonical_class.SignatureType();
1446 } 1446 }
1447 // Return the first canonical signature type if already computed. 1447 // Return the first canonical signature type if already computed at class
1448 // finalization time. The optimizer may canonicalize instantiated function
1449 // types of the same signature class, but these will be added after the
1450 // uninstantiated signature class at index 0.
1448 const Array& signature_types = Array::Handle(canonical_types()); 1451 const Array& signature_types = Array::Handle(canonical_types());
1449 // The canonical_types array is initialized to the empty array. 1452 // The canonical_types array is initialized to the empty array.
1450 ASSERT(!signature_types.IsNull()); 1453 ASSERT(!signature_types.IsNull());
1451 if (signature_types.Length() > 0) { 1454 if (signature_types.Length() > 0) {
1452 // At most one signature type per signature class.
1453 ASSERT((signature_types.Length() == 1) ||
1454 ((signature_types.Length() == 2) &&
1455 (signature_types.At(1) == Type::null())));
1456 Type& signature_type = Type::Handle(); 1455 Type& signature_type = Type::Handle();
1457 signature_type ^= signature_types.At(0); 1456 signature_type ^= signature_types.At(0);
1458 ASSERT(!signature_type.IsNull()); 1457 ASSERT(!signature_type.IsNull());
1459 return signature_type.raw(); 1458 return signature_type.raw();
1460 } 1459 }
1461 // A signature class extends class Instance and is parameterized in the same 1460 // A signature class extends class Instance and is parameterized in the same
1462 // way as the owner class of its non-static signature function. 1461 // way as the owner class of its non-static signature function.
1463 // It is not type parameterized if its signature function is static. 1462 // It is not type parameterized if its signature function is static.
1464 // See Class::NewSignatureClass() for the setup of its type parameters. 1463 // See Class::NewSignatureClass() for the setup of its type parameters.
1465 // During type finalization, the type arguments of the super class of the 1464 // During type finalization, the type arguments of the super class of the
(...skipping 9083 matching lines...) Expand 10 before | Expand all | Expand 10 after
10549 // list of canonicalized types. 10548 // list of canonicalized types.
10550 // TODO(asiva): Try to re-factor this lookup code to make sharing 10549 // TODO(asiva): Try to re-factor this lookup code to make sharing
10551 // easy between the 4 versions of this loop. 10550 // easy between the 4 versions of this loop.
10552 Type& type = Type::Handle(); 10551 Type& type = Type::Handle();
10553 intptr_t index = 0; 10552 intptr_t index = 0;
10554 while (index < canonical_types_len) { 10553 while (index < canonical_types_len) {
10555 type ^= canonical_types.At(index); 10554 type ^= canonical_types.At(index);
10556 if (type.IsNull()) { 10555 if (type.IsNull()) {
10557 break; 10556 break;
10558 } 10557 }
10559 if (!type.IsFinalized()) { 10558 ASSERT(type.IsFinalized());
10560 ASSERT((index == 0) && cls.IsSignatureClass());
10561 index++;
10562 continue;
10563 }
10564 if (this->Equals(type)) { 10559 if (this->Equals(type)) {
10565 return type.raw(); 10560 return type.raw();
10566 } 10561 }
10567 index++; 10562 index++;
10568 } 10563 }
10569 // Canonicalize the type arguments. 10564 // Canonicalize the type arguments.
10570 AbstractTypeArguments& type_args = AbstractTypeArguments::Handle(arguments()); 10565 AbstractTypeArguments& type_args = AbstractTypeArguments::Handle(arguments());
10571 type_args = type_args.Canonicalize(); 10566 type_args = type_args.Canonicalize();
10572 set_arguments(type_args); 10567 set_arguments(type_args);
10573 // The type needs to be added to the list. Grow the list if it is full. 10568 // The type needs to be added to the list. Grow the list if it is full.
10574 if (index == canonical_types_len) { 10569 if (index == canonical_types_len) {
10575 const intptr_t kLengthIncrement = 2; // Raw and parameterized. 10570 const intptr_t kLengthIncrement = 2; // Raw and parameterized.
10576 const intptr_t new_length = canonical_types.Length() + kLengthIncrement; 10571 const intptr_t new_length = canonical_types.Length() + kLengthIncrement;
10577 const Array& new_canonical_types = 10572 const Array& new_canonical_types =
10578 Array::Handle(Array::Grow(canonical_types, new_length, Heap::kOld)); 10573 Array::Handle(Array::Grow(canonical_types, new_length, Heap::kOld));
10579 cls.set_canonical_types(new_canonical_types); 10574 cls.set_canonical_types(new_canonical_types);
10580 new_canonical_types.SetAt(index, *this); 10575 new_canonical_types.SetAt(index, *this);
10581 } else { 10576 } else {
10582 canonical_types.SetAt(index, *this); 10577 canonical_types.SetAt(index, *this);
10583 } 10578 }
10579 #ifdef DEBUG
10580 if ((index == 0) && cls.IsCanonicalSignatureClass()) {
10581 // Verify that the first canonical type is the signature type by checking
10582 // that the type argument vector of the canonical type ends with the
10583 // uninstantiated type parameters of the signature class.
10584 // The signature type is finalized during class finalization, before the
10585 // optimizer may canonicalize instantiated function types of the same
10586 // signature class.
10587 // Although the signature class extends class Instance, the type arguments
10588 // of the super class of the owner class of its signature function will be
10589 // prepended to the type argument vector during class finalization.
10590 const TypeArguments& type_params =
10591 TypeArguments::Handle(cls.type_parameters());
10592 const intptr_t num_type_params = cls.NumTypeParameters();
10593 const intptr_t num_type_args = cls.NumTypeArguments();
10594 TypeParameter& type_arg = TypeParameter::Handle();
10595 TypeParameter& type_param = TypeParameter::Handle();
10596 for (intptr_t i = 0; i < num_type_params; i++) {
10597 type_arg ^= type_args.TypeAt(num_type_args - num_type_params + i);
10598 type_param ^= type_params.TypeAt(i);
10599 ASSERT(type_arg.Equals(type_param));
10600 }
10601 }
10602 #endif
10584 ASSERT(IsOld()); 10603 ASSERT(IsOld());
10585 SetCanonical(); 10604 SetCanonical();
10586 return this->raw(); 10605 return this->raw();
10587 } 10606 }
10588 10607
10589 10608
10590 intptr_t Type::Hash() const { 10609 intptr_t Type::Hash() const {
10591 ASSERT(IsFinalized()); 10610 ASSERT(IsFinalized());
10592 uword result = 1; 10611 uword result = 1;
10593 if (IsMalformed()) return result; 10612 if (IsMalformed()) return result;
(...skipping 3617 matching lines...) Expand 10 before | Expand all | Expand 10 after
14211 } 14230 }
14212 14231
14213 14232
14214 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14233 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14215 stream->OpenObject(); 14234 stream->OpenObject();
14216 stream->CloseObject(); 14235 stream->CloseObject();
14217 } 14236 }
14218 14237
14219 14238
14220 } // namespace dart 14239 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698