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

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

Issue 2965743002: [VM, generic functions reification, work in progress] (Closed)
Patch Set: Created 3 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
« runtime/vm/object.h ('K') | « 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/become.h" 10 #include "vm/become.h"
(...skipping 4843 matching lines...) Expand 10 before | Expand all | Expand 10 after
4854 return false; 4854 return false;
4855 } 4855 }
4856 } 4856 }
4857 return true; 4857 return true;
4858 } 4858 }
4859 4859
4860 4860
4861 bool TypeArguments::IsSubvectorInstantiated(intptr_t from_index, 4861 bool TypeArguments::IsSubvectorInstantiated(intptr_t from_index,
4862 intptr_t len, 4862 intptr_t len,
4863 Genericity genericity, 4863 Genericity genericity,
4864 intptr_t num_free_fun_type_params,
4864 TrailPtr trail) const { 4865 TrailPtr trail) const {
4865 ASSERT(!IsNull()); 4866 ASSERT(!IsNull());
4866 AbstractType& type = AbstractType::Handle(); 4867 AbstractType& type = AbstractType::Handle();
4867 for (intptr_t i = 0; i < len; i++) { 4868 for (intptr_t i = 0; i < len; i++) {
4868 type = TypeAt(from_index + i); 4869 type = TypeAt(from_index + i);
4869 // If this type argument T is null, the type A containing T in its flattened 4870 // If this type argument T is null, the type A containing T in its flattened
4870 // type argument vector V is recursive and is still being finalized. 4871 // type argument vector V is recursive and is still being finalized.
4871 // T is the type argument of a super type of A. T is being instantiated 4872 // T is the type argument of a super type of A. T is being instantiated
4872 // during finalization of V, which is also the instantiator. T depends 4873 // during finalization of V, which is also the instantiator. T depends
4873 // solely on the type parameters of A and will be replaced by a non-null 4874 // solely on the type parameters of A and will be replaced by a non-null
4874 // type before A is marked as finalized. 4875 // type before A is marked as finalized.
4875 if (!type.IsNull() && !type.IsInstantiated(genericity, trail)) { 4876 if (!type.IsNull() &&
4877 !type.IsInstantiated(genericity, num_free_fun_type_params, trail)) {
4876 return false; 4878 return false;
4877 } 4879 }
4878 } 4880 }
4879 return true; 4881 return true;
4880 } 4882 }
4881 4883
4882 4884
4883 bool TypeArguments::IsUninstantiatedIdentity() const { 4885 bool TypeArguments::IsUninstantiatedIdentity() const {
4884 AbstractType& type = AbstractType::Handle(); 4886 AbstractType& type = AbstractType::Handle();
4885 const intptr_t num_types = Length(); 4887 const intptr_t num_types = Length();
(...skipping 2362 matching lines...) Expand 10 before | Expand all | Expand 10 after
7248 BuildSignatureParameters(thread, zone, name_visibility, &pieces); 7250 BuildSignatureParameters(thread, zone, name_visibility, &pieces);
7249 pieces.Add(Symbols::RParenArrow()); 7251 pieces.Add(Symbols::RParenArrow());
7250 const AbstractType& res_type = AbstractType::Handle(zone, result_type()); 7252 const AbstractType& res_type = AbstractType::Handle(zone, result_type());
7251 name = res_type.BuildName(name_visibility); 7253 name = res_type.BuildName(name_visibility);
7252 pieces.Add(name); 7254 pieces.Add(name);
7253 return Symbols::FromConcatAll(thread, pieces); 7255 return Symbols::FromConcatAll(thread, pieces);
7254 } 7256 }
7255 7257
7256 7258
7257 bool Function::HasInstantiatedSignature(Genericity genericity, 7259 bool Function::HasInstantiatedSignature(Genericity genericity,
7260 intptr_t num_free_fun_type_params,
7258 TrailPtr trail) const { 7261 TrailPtr trail) const {
7262 if (genericity != kCurrentClass) {
7263 // We only consider the function type parameters declared by the parents of
7264 // this signature function.
7265 const int num_parent_type_params = NumParentTypeParameters();
7266 if (num_parent_type_params < num_free_fun_type_params) {
7267 num_free_fun_type_params = num_parent_type_params;
7268 }
7269 }
7259 AbstractType& type = AbstractType::Handle(result_type()); 7270 AbstractType& type = AbstractType::Handle(result_type());
7260 if (!type.IsInstantiated(genericity, trail)) { 7271 if (!type.IsInstantiated(genericity, num_free_fun_type_params, trail)) {
7261 return false; 7272 return false;
7262 } 7273 }
7263 const intptr_t num_parameters = NumParameters(); 7274 const intptr_t num_parameters = NumParameters();
7264 for (intptr_t i = 0; i < num_parameters; i++) { 7275 for (intptr_t i = 0; i < num_parameters; i++) {
7265 type = ParameterTypeAt(i); 7276 type = ParameterTypeAt(i);
7266 if (!type.IsInstantiated(genericity, trail)) { 7277 if (!type.IsInstantiated(genericity, num_free_fun_type_params, trail)) {
7267 return false; 7278 return false;
7268 } 7279 }
7269 } 7280 }
7270 return true; 7281 return true;
7271 } 7282 }
7272 7283
7273 7284
7274 RawClass* Function::Owner() const { 7285 RawClass* Function::Owner() const {
7275 if (raw_ptr()->owner_ == Object::null()) { 7286 if (raw_ptr()->owner_ == Object::null()) {
7276 ASSERT(IsSignatureFunction()); 7287 ASSERT(IsSignatureFunction());
(...skipping 9112 matching lines...) Expand 10 before | Expand all | Expand 10 after
16389 UNREACHABLE(); 16400 UNREACHABLE();
16390 } 16401 }
16391 16402
16392 TokenPosition AbstractType::token_pos() const { 16403 TokenPosition AbstractType::token_pos() const {
16393 // AbstractType is an abstract class. 16404 // AbstractType is an abstract class.
16394 UNREACHABLE(); 16405 UNREACHABLE();
16395 return TokenPosition::kNoSource; 16406 return TokenPosition::kNoSource;
16396 } 16407 }
16397 16408
16398 16409
16399 bool AbstractType::IsInstantiated(Genericity genericity, TrailPtr trail) const { 16410 bool AbstractType::IsInstantiated(Genericity genericity,
16411 intptr_t num_free_fun_type_params,
16412 TrailPtr trail) const {
16400 // AbstractType is an abstract class. 16413 // AbstractType is an abstract class.
16401 UNREACHABLE(); 16414 UNREACHABLE();
16402 return false; 16415 return false;
16403 } 16416 }
16404 16417
16405 16418
16406 bool AbstractType::IsFinalized() const { 16419 bool AbstractType::IsFinalized() const {
16407 // AbstractType is an abstract class. 16420 // AbstractType is an abstract class.
16408 UNREACHABLE(); 16421 UNREACHABLE();
16409 return false; 16422 return false;
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
17232 ASSERT(!unresolved_class.IsNull()); 17245 ASSERT(!unresolved_class.IsNull());
17233 return unresolved_class.raw(); 17246 return unresolved_class.raw();
17234 #else 17247 #else
17235 ASSERT(!Object::Handle(raw_ptr()->type_class_id_).IsNull()); 17248 ASSERT(!Object::Handle(raw_ptr()->type_class_id_).IsNull());
17236 ASSERT(Object::Handle(raw_ptr()->type_class_id_).IsUnresolvedClass()); 17249 ASSERT(Object::Handle(raw_ptr()->type_class_id_).IsUnresolvedClass());
17237 return reinterpret_cast<RawUnresolvedClass*>(raw_ptr()->type_class_id_); 17250 return reinterpret_cast<RawUnresolvedClass*>(raw_ptr()->type_class_id_);
17238 #endif 17251 #endif
17239 } 17252 }
17240 17253
17241 17254
17242 bool Type::IsInstantiated(Genericity genericity, TrailPtr trail) const { 17255 bool Type::IsInstantiated(Genericity genericity,
17256 intptr_t num_free_fun_type_params,
17257 TrailPtr trail) const {
17243 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) { 17258 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) {
17244 return true; 17259 return true;
17245 } 17260 }
17246 if ((genericity == kAny) && 17261 if ((genericity == kAny) && (num_free_fun_type_params == kMaxInt32) &&
17247 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated)) { 17262 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated)) {
17248 return false; 17263 return false;
17249 } 17264 }
17250 if (IsFunctionType()) { 17265 if (IsFunctionType()) {
17251 const Function& sig_fun = Function::Handle(signature()); 17266 const Function& sig_fun = Function::Handle(signature());
17252 if (!sig_fun.HasInstantiatedSignature(genericity, trail)) { 17267 if (!sig_fun.HasInstantiatedSignature(genericity, num_free_fun_type_params,
17268 trail)) {
17253 return false; 17269 return false;
17254 } 17270 }
17255 // Because a generic typedef with an instantiated signature is considered 17271 // Because a generic typedef with an instantiated signature is considered
17256 // uninstantiated, we still need to check the type arguments, even if the 17272 // uninstantiated, we still need to check the type arguments, even if the
17257 // signature is instantiated. 17273 // signature is instantiated.
17258 } 17274 }
17259 if (arguments() == TypeArguments::null()) { 17275 if (arguments() == TypeArguments::null()) {
17260 return true; 17276 return true;
17261 } 17277 }
17262 const TypeArguments& args = TypeArguments::Handle(arguments()); 17278 const TypeArguments& args = TypeArguments::Handle(arguments());
(...skipping 10 matching lines...) Expand all
17273 len = cls.NumTypeParameters(); // Check the type parameters only. 17289 len = cls.NumTypeParameters(); // Check the type parameters only.
17274 if (len > num_type_args) { 17290 if (len > num_type_args) {
17275 // This type has the wrong number of arguments and is not finalized yet. 17291 // This type has the wrong number of arguments and is not finalized yet.
17276 // Type arguments are reset to null when finalizing such a type. 17292 // Type arguments are reset to null when finalizing such a type.
17277 ASSERT(!IsFinalized()); 17293 ASSERT(!IsFinalized());
17278 len = num_type_args; 17294 len = num_type_args;
17279 } 17295 }
17280 } 17296 }
17281 return (len == 0) || 17297 return (len == 0) ||
17282 args.IsSubvectorInstantiated(num_type_args - len, len, genericity, 17298 args.IsSubvectorInstantiated(num_type_args - len, len, genericity,
17283 trail); 17299 num_free_fun_type_params, trail);
17284 } 17300 }
17285 17301
17286 17302
17287 RawAbstractType* Type::InstantiateFrom( 17303 RawAbstractType* Type::InstantiateFrom(
17288 const TypeArguments& instantiator_type_arguments, 17304 const TypeArguments& instantiator_type_arguments,
17289 const TypeArguments& function_type_arguments, 17305 const TypeArguments& function_type_arguments,
17290 Error* bound_error, 17306 Error* bound_error,
17291 TrailPtr instantiation_trail, 17307 TrailPtr instantiation_trail,
17292 TrailPtr bound_trail, 17308 TrailPtr bound_trail,
17293 Heap::Space space) const { 17309 Heap::Space space) const {
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
17990 const intptr_t hash = Hash(); 18006 const intptr_t hash = Hash();
17991 return OS::SCreate(zone, "Type: (@%p H%" Px ") class '%s', args:[%s]", 18007 return OS::SCreate(zone, "Type: (@%p H%" Px ") class '%s', args:[%s]",
17992 raw(), hash, class_name, args_cstr); 18008 raw(), hash, class_name, args_cstr);
17993 } else { 18009 } else {
17994 return OS::SCreate(zone, "%sType: class '%s', args:[%s]", unresolved, 18010 return OS::SCreate(zone, "%sType: class '%s', args:[%s]", unresolved,
17995 class_name, args_cstr); 18011 class_name, args_cstr);
17996 } 18012 }
17997 } 18013 }
17998 18014
17999 18015
18000 bool TypeRef::IsInstantiated(Genericity genericity, TrailPtr trail) const { 18016 bool TypeRef::IsInstantiated(Genericity genericity,
18017 intptr_t num_free_fun_type_params,
18018 TrailPtr trail) const {
18001 if (TestAndAddToTrail(&trail)) { 18019 if (TestAndAddToTrail(&trail)) {
18002 return true; 18020 return true;
18003 } 18021 }
18004 const AbstractType& ref_type = AbstractType::Handle(type()); 18022 const AbstractType& ref_type = AbstractType::Handle(type());
18005 return !ref_type.IsNull() && ref_type.IsInstantiated(genericity, trail); 18023 return !ref_type.IsNull() &&
18024 ref_type.IsInstantiated(genericity, num_free_fun_type_params, trail);
18006 } 18025 }
18007 18026
18008 18027
18009 bool TypeRef::IsEquivalent(const Instance& other, TrailPtr trail) const { 18028 bool TypeRef::IsEquivalent(const Instance& other, TrailPtr trail) const {
18010 if (raw() == other.raw()) { 18029 if (raw() == other.raw()) {
18011 return true; 18030 return true;
18012 } 18031 }
18013 if (!other.IsAbstractType()) { 18032 if (!other.IsAbstractType()) {
18014 return false; 18033 return false;
18015 } 18034 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
18162 } 18181 }
18163 18182
18164 18183
18165 void TypeParameter::SetIsFinalized() const { 18184 void TypeParameter::SetIsFinalized() const {
18166 ASSERT(!IsFinalized()); 18185 ASSERT(!IsFinalized());
18167 set_type_state(RawTypeParameter::kFinalizedUninstantiated); 18186 set_type_state(RawTypeParameter::kFinalizedUninstantiated);
18168 } 18187 }
18169 18188
18170 18189
18171 bool TypeParameter::IsInstantiated(Genericity genericity, 18190 bool TypeParameter::IsInstantiated(Genericity genericity,
18191 intptr_t num_free_fun_type_params,
18172 TrailPtr trail) const { 18192 TrailPtr trail) const {
18173 switch (genericity) { 18193 if (IsClassTypeParameter()) {
18174 case kAny: 18194 return genericity == kFunctions;
18175 return false;
18176 case kCurrentClass:
18177 return IsFunctionTypeParameter();
18178 case kFunctions:
18179 return IsClassTypeParameter();
18180 default:
18181 UNREACHABLE();
18182 } 18195 }
18183 return false; 18196 ASSERT(IsFunctionTypeParameter());
18197 ASSERT(IsFinalized());
18198 return (genericity == kCurrentClass) || (index() >= num_free_fun_type_params);
18184 } 18199 }
18185 18200
18186 18201
18187 bool TypeParameter::IsEquivalent(const Instance& other, TrailPtr trail) const { 18202 bool TypeParameter::IsEquivalent(const Instance& other, TrailPtr trail) const {
18188 if (raw() == other.raw()) { 18203 if (raw() == other.raw()) {
18189 return true; 18204 return true;
18190 } 18205 }
18191 if (other.IsTypeRef()) { 18206 if (other.IsTypeRef()) {
18192 // Unfold right hand type. Divergence is controlled by left hand type. 18207 // Unfold right hand type. Divergence is controlled by left hand type.
18193 const AbstractType& other_ref_type = 18208 const AbstractType& other_ref_type =
(...skipping 5359 matching lines...) Expand 10 before | Expand all | Expand 10 after
23553 return UserTag::null(); 23568 return UserTag::null();
23554 } 23569 }
23555 23570
23556 23571
23557 const char* UserTag::ToCString() const { 23572 const char* UserTag::ToCString() const {
23558 const String& tag_label = String::Handle(label()); 23573 const String& tag_label = String::Handle(label());
23559 return tag_label.ToCString(); 23574 return tag_label.ToCString();
23560 } 23575 }
23561 23576
23562 } // namespace dart 23577 } // namespace dart
OLDNEW
« runtime/vm/object.h ('K') | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698