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

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

Issue 211963003: Detect and reject illegal recursive types (non-contractive types). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 8 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
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 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 1293
1294 // Check the 'more specific' relationship, considering only a subvector of 1294 // Check the 'more specific' relationship, considering only a subvector of
1295 // length 'len' starting at 'from_index'. 1295 // length 'len' starting at 'from_index'.
1296 bool IsMoreSpecificThan(const TypeArguments& other, 1296 bool IsMoreSpecificThan(const TypeArguments& other,
1297 intptr_t from_index, 1297 intptr_t from_index,
1298 intptr_t len, 1298 intptr_t len,
1299 Error* bound_error) const { 1299 Error* bound_error) const {
1300 return TypeTest(kIsMoreSpecificThan, other, from_index, len, bound_error); 1300 return TypeTest(kIsMoreSpecificThan, other, from_index, len, bound_error);
1301 } 1301 }
1302 1302
1303 // Check if the vectors are equal. 1303 // Check if the vectors are equal (they may be null).
1304 bool Equals(const TypeArguments& other) const { 1304 bool Equals(const TypeArguments& other) const {
1305 return IsEquivalent(other); 1305 return IsSubvectorEquivalent(other, 0, IsNull() ? 0 : Length());
1306 } 1306 }
1307 1307
1308 bool IsEquivalent(const TypeArguments& other, 1308 bool IsEquivalent(const TypeArguments& other,
1309 GrowableObjectArray* trail = NULL) const; 1309 GrowableObjectArray* trail = NULL) const {
1310 return IsSubvectorEquivalent(other, 0, IsNull() ? 0 : Length(), trail);
1311 }
1312 bool IsSubvectorEquivalent(const TypeArguments& other,
1313 intptr_t from_index,
1314 intptr_t len,
1315 GrowableObjectArray* trail = NULL) const;
1310 1316
1311 bool IsInstantiated(GrowableObjectArray* trail = NULL) const; 1317 // Check if the vector is instantiated (it must not be null).
1318 bool IsInstantiated(GrowableObjectArray* trail = NULL) const {
1319 return IsSubvectorInstantiated(0, Length(), trail);
1320 }
1321 bool IsSubvectorInstantiated(intptr_t from_index,
1322 intptr_t len,
1323 GrowableObjectArray* trail = NULL) const;
1312 bool IsUninstantiatedIdentity() const; 1324 bool IsUninstantiatedIdentity() const;
1313 bool CanShareInstantiatorTypeArguments(const Class& instantiator_class) const; 1325 bool CanShareInstantiatorTypeArguments(const Class& instantiator_class) const;
1314 1326
1315 // Returns true if all types of this vector are respectively, resolved, 1327 // Return true if all types of this vector are respectively, resolved,
1316 // finalized, or bounded. 1328 // finalized, or bounded.
1317 bool IsResolved() const; 1329 bool IsResolved() const;
1318 bool IsFinalized() const; 1330 bool IsFinalized() const;
1319 bool IsBounded() const; 1331 bool IsBounded() const;
1320 1332
1333 // Return true if this vector contains a recursive type argument.
1334 bool IsRecursive() const;
1335
1321 // Clone this type argument vector and clone all unfinalized type arguments. 1336 // Clone this type argument vector and clone all unfinalized type arguments.
1322 // Finalized type arguments are shared. 1337 // Finalized type arguments are shared.
1323 RawTypeArguments* CloneUnfinalized() const; 1338 RawTypeArguments* CloneUnfinalized() const;
1324 1339
1325 // Canonicalize only if instantiated, otherwise returns 'this'. 1340 // Canonicalize only if instantiated, otherwise returns 'this'.
1326 RawTypeArguments* Canonicalize(GrowableObjectArray* trail = NULL) const; 1341 RawTypeArguments* Canonicalize(GrowableObjectArray* trail = NULL) const;
1327 1342
1328 // Return 'this' if this type argument vector is instantiated, i.e. if it does 1343 // Return 'this' if this type argument vector is instantiated, i.e. if it does
1329 // not refer to type parameters. Otherwise, return a new type argument vector 1344 // not refer to type parameters. Otherwise, return a new type argument vector
1330 // where each reference to a type parameter is replaced with the corresponding 1345 // where each reference to a type parameter is replaced with the corresponding
(...skipping 2791 matching lines...) Expand 10 before | Expand all | Expand 10 after
4122 virtual RawClass* type_class() const; 4137 virtual RawClass* type_class() const;
4123 virtual RawUnresolvedClass* unresolved_class() const; 4138 virtual RawUnresolvedClass* unresolved_class() const;
4124 virtual RawTypeArguments* arguments() const; 4139 virtual RawTypeArguments* arguments() const;
4125 virtual intptr_t token_pos() const; 4140 virtual intptr_t token_pos() const;
4126 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const; 4141 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const;
4127 virtual bool Equals(const Instance& other) const { 4142 virtual bool Equals(const Instance& other) const {
4128 return IsEquivalent(other); 4143 return IsEquivalent(other);
4129 } 4144 }
4130 virtual bool IsEquivalent(const Instance& other, 4145 virtual bool IsEquivalent(const Instance& other,
4131 GrowableObjectArray* trail = NULL) const; 4146 GrowableObjectArray* trail = NULL) const;
4147 virtual bool IsRecursive() const;
4132 4148
4133 // Instantiate this type using the given type argument vector. 4149 // Instantiate this type using the given type argument vector.
4134 // Return a new type, or return 'this' if it is already instantiated. 4150 // Return a new type, or return 'this' if it is already instantiated.
4135 // If bound_error is not NULL, it may be set to reflect a bound error. 4151 // If bound_error is not NULL, it may be set to reflect a bound error.
4136 virtual RawAbstractType* InstantiateFrom( 4152 virtual RawAbstractType* InstantiateFrom(
4137 const TypeArguments& instantiator_type_arguments, 4153 const TypeArguments& instantiator_type_arguments,
4138 Error* bound_error, 4154 Error* bound_error,
4139 GrowableObjectArray* trail = NULL) const; 4155 GrowableObjectArray* trail = NULL) const;
4140 4156
4141 // Return a clone of this unfinalized type or the type itself if it is 4157 // Return a clone of this unfinalized type or the type itself if it is
4142 // already finalized. Apply recursively to type arguments, i.e. finalized 4158 // already finalized. Apply recursively to type arguments, i.e. finalized
4143 // type arguments of an unfinalized type are not cloned, but shared. 4159 // type arguments of an unfinalized type are not cloned, but shared.
4144 virtual RawAbstractType* CloneUnfinalized() const; 4160 virtual RawAbstractType* CloneUnfinalized() const;
4145 4161
4146 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const { 4162 virtual RawInstance* CheckAndCanonicalize(const char** error_str) const {
4147 return Canonicalize(); 4163 return Canonicalize();
4148 } 4164 }
4149 4165
4150 // Return the canonical version of this type. 4166 // Return the canonical version of this type.
4151 virtual RawAbstractType* Canonicalize( 4167 virtual RawAbstractType* Canonicalize(
4152 GrowableObjectArray* trail = NULL) const; 4168 GrowableObjectArray* trail = NULL) const;
4153 4169
4170 // Return the object associated with the receiver in the trail or
4171 // Object::null() if the receiver is not contained in the trail.
4172 RawObject* OnlyBuddyInTrail(GrowableObjectArray* trail) const;
4173
4174 // If the trail is null, allocate a trail, add the pair <receiver, buddy> to
4175 // the trail. The receiver may only be added once with its only buddy.
4176 void AddOnlyBuddyToTrail(GrowableObjectArray** trail,
4177 const Object& buddy) const;
4178
4154 // The name of this type, including the names of its type arguments, if any. 4179 // The name of this type, including the names of its type arguments, if any.
4155 virtual RawString* Name() const { 4180 virtual RawString* Name() const {
4156 return BuildName(kInternalName); 4181 return BuildName(kInternalName);
4157 } 4182 }
4158 4183
4159 // The name of this type, including the names of its type arguments, if any. 4184 // The name of this type, including the names of its type arguments, if any.
4160 // Names of internal classes are mapped to their public interfaces. 4185 // Names of internal classes are mapped to their public interfaces.
4161 virtual RawString* UserVisibleName() const { 4186 virtual RawString* UserVisibleName() const {
4162 return BuildName(kUserVisibleName); 4187 return BuildName(kUserVisibleName);
4163 } 4188 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
4277 virtual bool HasResolvedTypeClass() const; // Own type class resolved. 4302 virtual bool HasResolvedTypeClass() const; // Own type class resolved.
4278 virtual RawClass* type_class() const; 4303 virtual RawClass* type_class() const;
4279 void set_type_class(const Object& value) const; 4304 void set_type_class(const Object& value) const;
4280 virtual RawUnresolvedClass* unresolved_class() const; 4305 virtual RawUnresolvedClass* unresolved_class() const;
4281 virtual RawTypeArguments* arguments() const; 4306 virtual RawTypeArguments* arguments() const;
4282 void set_arguments(const TypeArguments& value) const; 4307 void set_arguments(const TypeArguments& value) const;
4283 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; } 4308 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; }
4284 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const; 4309 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const;
4285 virtual bool IsEquivalent(const Instance& other, 4310 virtual bool IsEquivalent(const Instance& other,
4286 GrowableObjectArray* trail = NULL) const; 4311 GrowableObjectArray* trail = NULL) const;
4312 virtual bool IsRecursive() const;
4287 virtual RawAbstractType* InstantiateFrom( 4313 virtual RawAbstractType* InstantiateFrom(
4288 const TypeArguments& instantiator_type_arguments, 4314 const TypeArguments& instantiator_type_arguments,
4289 Error* malformed_error, 4315 Error* malformed_error,
4290 GrowableObjectArray* trail = NULL) const; 4316 GrowableObjectArray* trail = NULL) const;
4291 virtual RawAbstractType* CloneUnfinalized() const; 4317 virtual RawAbstractType* CloneUnfinalized() const;
4292 virtual RawAbstractType* Canonicalize( 4318 virtual RawAbstractType* Canonicalize(
4293 GrowableObjectArray* trail = NULL) const; 4319 GrowableObjectArray* trail = NULL) const;
4294 4320
4295 virtual intptr_t Hash() const; 4321 virtual intptr_t Hash() const;
4296 4322
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
4395 } 4421 }
4396 virtual RawTypeArguments* arguments() const { 4422 virtual RawTypeArguments* arguments() const {
4397 return AbstractType::Handle(type()).arguments(); 4423 return AbstractType::Handle(type()).arguments();
4398 } 4424 }
4399 virtual intptr_t token_pos() const { 4425 virtual intptr_t token_pos() const {
4400 return AbstractType::Handle(type()).token_pos(); 4426 return AbstractType::Handle(type()).token_pos();
4401 } 4427 }
4402 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const; 4428 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const;
4403 virtual bool IsEquivalent(const Instance& other, 4429 virtual bool IsEquivalent(const Instance& other,
4404 GrowableObjectArray* trail = NULL) const; 4430 GrowableObjectArray* trail = NULL) const;
4431 virtual bool IsRecursive() const { return true; }
4405 virtual RawAbstractType* InstantiateFrom( 4432 virtual RawAbstractType* InstantiateFrom(
4406 const TypeArguments& instantiator_type_arguments, 4433 const TypeArguments& instantiator_type_arguments,
4407 Error* bound_error, 4434 Error* bound_error,
4408 GrowableObjectArray* trail = NULL) const; 4435 GrowableObjectArray* trail = NULL) const;
4409 virtual RawAbstractType* Canonicalize( 4436 virtual RawAbstractType* Canonicalize(
4410 GrowableObjectArray* trail = NULL) const; 4437 GrowableObjectArray* trail = NULL) const;
4411 4438
4412 virtual intptr_t Hash() const; 4439 virtual intptr_t Hash() const;
4413 4440
4414 // Return true if the receiver is contained in the trail. 4441 // Return true if the receiver is contained in the trail.
4415 // Otherwise, if the trail is null, allocate a trail, then add the receiver to 4442 // Otherwise, if the trail is null, allocate a trail, then add the receiver to
4416 // the trail and return false. 4443 // the trail and return false.
4417 bool TestAndAddToTrail(GrowableObjectArray** trail) const; 4444 bool TestAndAddToTrail(GrowableObjectArray** trail) const;
4418 4445
4419 // Return true if the pair <receiver, buddy> is contained in the trail. 4446 // Return true if the pair <receiver, buddy> is contained in the trail.
4420 // Otherwise, if the trail is null, allocate a trail, add the pair <receiver, 4447 // Otherwise, if the trail is null, allocate a trail, add the pair <receiver,
4421 // buddy> to the trail and return false. 4448 // buddy> to the trail and return false.
4422 // The receiver may be added several times, each time with a different buddy. 4449 // The receiver may be added several times, each time with a different buddy.
4423 bool TestAndAddBuddyToTrail(GrowableObjectArray** trail, 4450 bool TestAndAddBuddyToTrail(GrowableObjectArray** trail,
4424 const Object& buddy) const; 4451 const Object& buddy) const;
4425 4452
4426 // Return the object associated with the receiver in the trail or
4427 // Object::null() if the receiver is not contained in the trail.
4428 RawObject* OnlyBuddyInTrail(GrowableObjectArray* trail) const;
4429
4430 // If the trail is null, allocate a trail, add the pair <receiver, buddy> to
4431 // the trail. The receiver may only be added once with its only buddy.
4432 void AddOnlyBuddyToTrail(GrowableObjectArray** trail,
4433 const Object& buddy) const;
4434
4435 static intptr_t InstanceSize() { 4453 static intptr_t InstanceSize() {
4436 return RoundedAllocationSize(sizeof(RawTypeRef)); 4454 return RoundedAllocationSize(sizeof(RawTypeRef));
4437 } 4455 }
4438 4456
4439 static RawTypeRef* New(const AbstractType& type); 4457 static RawTypeRef* New(const AbstractType& type);
4440 4458
4441 private: 4459 private:
4442 static RawTypeRef* New(); 4460 static RawTypeRef* New();
4443 4461
4444 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeRef, AbstractType); 4462 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeRef, AbstractType);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
4483 // bound cannot be checked yet and this is not an error. 4501 // bound cannot be checked yet and this is not an error.
4484 bool CheckBound(const AbstractType& bounded_type, 4502 bool CheckBound(const AbstractType& bounded_type,
4485 const AbstractType& upper_bound, 4503 const AbstractType& upper_bound,
4486 Error* bound_error) const; 4504 Error* bound_error) const;
4487 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; } 4505 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; }
4488 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const { 4506 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const {
4489 return false; 4507 return false;
4490 } 4508 }
4491 virtual bool IsEquivalent(const Instance& other, 4509 virtual bool IsEquivalent(const Instance& other,
4492 GrowableObjectArray* trail = NULL) const; 4510 GrowableObjectArray* trail = NULL) const;
4511 virtual bool IsRecursive() const { return false; }
4493 virtual RawAbstractType* InstantiateFrom( 4512 virtual RawAbstractType* InstantiateFrom(
4494 const TypeArguments& instantiator_type_arguments, 4513 const TypeArguments& instantiator_type_arguments,
4495 Error* bound_error, 4514 Error* bound_error,
4496 GrowableObjectArray* trail = NULL) const; 4515 GrowableObjectArray* trail = NULL) const;
4497 virtual RawAbstractType* CloneUnfinalized() const; 4516 virtual RawAbstractType* CloneUnfinalized() const;
4498 virtual RawAbstractType* Canonicalize( 4517 virtual RawAbstractType* Canonicalize(
4499 GrowableObjectArray* trail = NULL) const { 4518 GrowableObjectArray* trail = NULL) const {
4500 return raw(); 4519 return raw();
4501 } 4520 }
4502 4521
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
4566 } 4585 }
4567 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const { 4586 virtual bool IsInstantiated(GrowableObjectArray* trail = NULL) const {
4568 // It is not possible to encounter an instantiated bounded type with an 4587 // It is not possible to encounter an instantiated bounded type with an
4569 // uninstantiated upper bound. Therefore, we do not need to check if the 4588 // uninstantiated upper bound. Therefore, we do not need to check if the
4570 // bound is instantiated. Moreover, doing so could lead into cycles, as in 4589 // bound is instantiated. Moreover, doing so could lead into cycles, as in
4571 // class C<T extends C<C>> { }. 4590 // class C<T extends C<C>> { }.
4572 return AbstractType::Handle(type()).IsInstantiated(); 4591 return AbstractType::Handle(type()).IsInstantiated();
4573 } 4592 }
4574 virtual bool IsEquivalent(const Instance& other, 4593 virtual bool IsEquivalent(const Instance& other,
4575 GrowableObjectArray* trail = NULL) const; 4594 GrowableObjectArray* trail = NULL) const;
4595 virtual bool IsRecursive() const;
4576 virtual RawAbstractType* InstantiateFrom( 4596 virtual RawAbstractType* InstantiateFrom(
4577 const TypeArguments& instantiator_type_arguments, 4597 const TypeArguments& instantiator_type_arguments,
4578 Error* bound_error, 4598 Error* bound_error,
4579 GrowableObjectArray* trail = NULL) const; 4599 GrowableObjectArray* trail = NULL) const;
4580 virtual RawAbstractType* CloneUnfinalized() const; 4600 virtual RawAbstractType* CloneUnfinalized() const;
4581 virtual RawAbstractType* Canonicalize( 4601 virtual RawAbstractType* Canonicalize(
4582 GrowableObjectArray* trail = NULL) const { 4602 GrowableObjectArray* trail = NULL) const {
4583 return raw(); 4603 return raw();
4584 } 4604 }
4585 4605
(...skipping 2170 matching lines...) Expand 10 before | Expand all | Expand 10 after
6756 6776
6757 6777
6758 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 6778 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
6759 intptr_t index) { 6779 intptr_t index) {
6760 return array.At((index * kEntryLength) + kTargetFunctionIndex); 6780 return array.At((index * kEntryLength) + kTargetFunctionIndex);
6761 } 6781 }
6762 6782
6763 } // namespace dart 6783 } // namespace dart
6764 6784
6765 #endif // VM_OBJECT_H_ 6785 #endif // VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698