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

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

Issue 81363002: Improve type test and type equality for generics (issue 15148). (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/flow_graph_optimizer.cc ('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) 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 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 1180
1181 1181
1182 // AbstractTypeArguments is an abstract superclass. 1182 // AbstractTypeArguments is an abstract superclass.
1183 // Subclasses of AbstractTypeArguments are TypeArguments and 1183 // Subclasses of AbstractTypeArguments are TypeArguments and
1184 // InstantiatedTypeArguments. 1184 // InstantiatedTypeArguments.
1185 class AbstractTypeArguments : public Object { 1185 class AbstractTypeArguments : public Object {
1186 public: 1186 public:
1187 // Returns true if all types of this vector are finalized. 1187 // Returns true if all types of this vector are finalized.
1188 virtual bool IsFinalized() const { return true; } 1188 virtual bool IsFinalized() const { return true; }
1189 1189
1190 // Returns true if both arguments represent vectors of equal types.
1191 static bool AreEqual(const AbstractTypeArguments& arguments,
1192 const AbstractTypeArguments& other_arguments);
1193
1194 // Return 'this' if this type argument vector is instantiated, i.e. if it does 1190 // Return 'this' if this type argument vector is instantiated, i.e. if it does
1195 // not refer to type parameters. Otherwise, return a new type argument vector 1191 // not refer to type parameters. Otherwise, return a new type argument vector
1196 // where each reference to a type parameter is replaced with the corresponding 1192 // where each reference to a type parameter is replaced with the corresponding
1197 // type of the instantiator type argument vector. 1193 // type of the instantiator type argument vector.
1198 // If bound_error is not NULL, it may be set to reflect a bound error. 1194 // If bound_error is not NULL, it may be set to reflect a bound error.
1199 virtual RawAbstractTypeArguments* InstantiateFrom( 1195 virtual RawAbstractTypeArguments* InstantiateFrom(
1200 const AbstractTypeArguments& instantiator_type_arguments, 1196 const AbstractTypeArguments& instantiator_type_arguments,
1201 Error* bound_error) const; 1197 Error* bound_error) const;
1202 1198
1203 // Do not clone InstantiatedTypeArguments or null vectors, since they are 1199 // Do not clone InstantiatedTypeArguments or null vectors, since they are
1204 // considered finalized. 1200 // considered finalized.
1205 virtual RawAbstractTypeArguments* CloneUnfinalized() const { 1201 virtual RawAbstractTypeArguments* CloneUnfinalized() const {
1206 return this->raw(); 1202 return this->raw();
1207 } 1203 }
1208 1204
1209 // Do not canonicalize InstantiatedTypeArguments or null vectors. 1205 // Do not canonicalize InstantiatedTypeArguments or null vectors.
1210 virtual RawAbstractTypeArguments* Canonicalize() const { return this->raw(); } 1206 virtual RawAbstractTypeArguments* Canonicalize() const { return this->raw(); }
1211 1207
1212 // The name of this type argument vector, e.g. "<T, dynamic, List<T>, Smi>". 1208 // The name of this type argument vector, e.g. "<T, dynamic, List<T>, Smi>".
1213 virtual RawString* Name() const { 1209 virtual RawString* Name() const {
1214 return SubvectorName(0, Length(), kInternalName); 1210 return SubvectorName(0, Length(), kInternalName);
1215 } 1211 }
1216 1212
1217 // The name of this type argument vector, e.g. "<T, dynamic, List<T>, int>". 1213 // The name of this type argument vector, e.g. "<T, dynamic, List<T>, int>".
1218 // Names of internal classes are mapped to their public interfaces. 1214 // Names of internal classes are mapped to their public interfaces.
1219 virtual RawString* UserVisibleName() const { 1215 virtual RawString* UserVisibleName() const {
1220 return SubvectorName(0, Length(), kUserVisibleName); 1216 return SubvectorName(0, Length(), kUserVisibleName);
1221 } 1217 }
1222 1218
1223 // Check if this type argument vector consists solely of DynamicType, 1219 // Check if the subvector of length 'len' starting at 'from_index' of this
1224 // considering only a prefix of length 'len'. 1220 // type argument vector consists solely of DynamicType.
1225 bool IsRaw(intptr_t len) const { 1221 bool IsRaw(intptr_t from_index, intptr_t len) const {
1226 return IsDynamicTypes(false, len); 1222 return IsDynamicTypes(false, from_index, len);
1227 } 1223 }
1228 1224
1229 // Check if this type argument vector would consist solely of DynamicType if 1225 // Check if this type argument vector would consist solely of DynamicType if
1230 // it was instantiated from a raw (null) instantiator, i.e. consider each type 1226 // it was instantiated from a raw (null) instantiator, i.e. consider each type
1231 // parameter as it would be first instantiated from a vector of dynamic types. 1227 // parameter as it would be first instantiated from a vector of dynamic types.
1232 // Consider only a prefix of length 'len'. 1228 // Consider only a prefix of length 'len'.
1233 bool IsRawInstantiatedRaw(intptr_t len) const { 1229 bool IsRawInstantiatedRaw(intptr_t len) const {
1234 return IsDynamicTypes(true, len); 1230 return IsDynamicTypes(true, 0, len);
1235 } 1231 }
1236 1232
1237 // Check the subtype relationship, considering only a prefix of length 'len'. 1233 // Check the subtype relationship, considering only a subvector of length
1234 // 'len' starting at 'from_index'.
1238 bool IsSubtypeOf(const AbstractTypeArguments& other, 1235 bool IsSubtypeOf(const AbstractTypeArguments& other,
1236 intptr_t from_index,
1239 intptr_t len, 1237 intptr_t len,
1240 Error* bound_error) const { 1238 Error* bound_error) const {
1241 return TypeTest(kIsSubtypeOf, other, len, bound_error); 1239 return TypeTest(kIsSubtypeOf, other, from_index, len, bound_error);
1242 } 1240 }
1243 1241
1244 // Check the 'more specific' relationship, considering only a prefix of 1242 // Check the 'more specific' relationship, considering only a subvector of
1245 // length 'len'. 1243 // length 'len' starting at 'from_index'.
1246 bool IsMoreSpecificThan(const AbstractTypeArguments& other, 1244 bool IsMoreSpecificThan(const AbstractTypeArguments& other,
1245 intptr_t from_index,
1247 intptr_t len, 1246 intptr_t len,
1248 Error* bound_error) const { 1247 Error* bound_error) const {
1249 return TypeTest(kIsMoreSpecificThan, other, len, bound_error); 1248 return TypeTest(kIsMoreSpecificThan, other, from_index, len, bound_error);
1250 } 1249 }
1251 1250
1251 // Check if the vectors are equal.
1252 bool Equals(const AbstractTypeArguments& other) const; 1252 bool Equals(const AbstractTypeArguments& other) const;
1253 1253
1254 // UNREACHABLEs as AbstractTypeArguments is an abstract class. 1254 // UNREACHABLEs as AbstractTypeArguments is an abstract class.
1255 virtual intptr_t Length() const; 1255 virtual intptr_t Length() const;
1256 virtual RawAbstractType* TypeAt(intptr_t index) const; 1256 virtual RawAbstractType* TypeAt(intptr_t index) const;
1257 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const; 1257 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const;
1258 virtual bool IsResolved() const; 1258 virtual bool IsResolved() const;
1259 virtual bool IsInstantiated() const; 1259 virtual bool IsInstantiated() const;
1260 virtual bool IsUninstantiatedIdentity() const; 1260 virtual bool IsUninstantiatedIdentity() const;
1261 virtual bool CanShareInstantiatorTypeArguments( 1261 virtual bool CanShareInstantiatorTypeArguments(
1262 const Class& instantiator_class) const; 1262 const Class& instantiator_class) const;
1263 virtual bool IsBounded() const; 1263 virtual bool IsBounded() const;
1264 1264
1265 virtual intptr_t Hash() const; 1265 virtual intptr_t Hash() const;
1266 1266
1267 private: 1267 private:
1268 // Check if this type argument vector consists solely of DynamicType, 1268 // Check if the subvector of length 'len' starting at 'from_index' of this
1269 // considering only a prefix of length 'len'. 1269 // type argument vector consists solely of DynamicType.
1270 // If raw_instantiated is true, consider each type parameter to be first 1270 // If raw_instantiated is true, consider each type parameter to be first
1271 // instantiated from a vector of dynamic types. 1271 // instantiated from a vector of dynamic types.
1272 bool IsDynamicTypes(bool raw_instantiated, intptr_t len) const; 1272 bool IsDynamicTypes(bool raw_instantiated,
1273 intptr_t from_index,
1274 intptr_t len) const;
1273 1275
1274 // Check the subtype or 'more specific' relationship, considering only a 1276 // Check the subtype or 'more specific' relationship, considering only a
1275 // prefix of length 'len'. 1277 // subvector of length 'len' starting at 'from_index'.
1276 bool TypeTest(TypeTestKind test_kind, 1278 bool TypeTest(TypeTestKind test_kind,
1277 const AbstractTypeArguments& other, 1279 const AbstractTypeArguments& other,
1280 intptr_t from_index,
1278 intptr_t len, 1281 intptr_t len,
1279 Error* bound_error) const; 1282 Error* bound_error) const;
1280 1283
1281 // Return the internal or public name of a subvector of this type argument 1284 // Return the internal or public name of a subvector of this type argument
1282 // vector, e.g. "<T, dynamic, List<T>, int>". 1285 // vector, e.g. "<T, dynamic, List<T>, int>".
1283 RawString* SubvectorName(intptr_t from_index, 1286 RawString* SubvectorName(intptr_t from_index,
1284 intptr_t len, 1287 intptr_t len,
1285 NameVisibility name_visibility) const; 1288 NameVisibility name_visibility) const;
1286 1289
1287 protected: 1290 protected:
(...skipping 5138 matching lines...) Expand 10 before | Expand all | Expand 10 after
6426 6429
6427 6430
6428 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 6431 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
6429 intptr_t index) { 6432 intptr_t index) {
6430 return array.At((index * kEntryLength) + kTargetFunctionIndex); 6433 return array.At((index * kEntryLength) + kTargetFunctionIndex);
6431 } 6434 }
6432 6435
6433 } // namespace dart 6436 } // namespace dart
6434 6437
6435 #endif // VM_OBJECT_H_ 6438 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_optimizer.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698