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

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

Issue 2979763002: [VM generic function types] Properly set the scope function after parsing a (Closed)
Patch Set: work in progress 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
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 RUNTIME_VM_OBJECT_H_ 5 #ifndef RUNTIME_VM_OBJECT_H_
6 #define RUNTIME_VM_OBJECT_H_ 6 #define RUNTIME_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 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 1672
1673 // Return true if all types of this vector are respectively, resolved, 1673 // Return true if all types of this vector are respectively, resolved,
1674 // finalized, or bounded. 1674 // finalized, or bounded.
1675 bool IsResolved() const; 1675 bool IsResolved() const;
1676 bool IsFinalized() const; 1676 bool IsFinalized() const;
1677 bool IsBounded() const; 1677 bool IsBounded() const;
1678 1678
1679 // Return true if this vector contains a recursive type argument. 1679 // Return true if this vector contains a recursive type argument.
1680 bool IsRecursive() const; 1680 bool IsRecursive() const;
1681 1681
1682 // Set the scope of this type argument vector to the given function.
1683 void SetScopeFunction(const Function& function) const;
1684
1682 // Clone this type argument vector and clone all unfinalized type arguments. 1685 // Clone this type argument vector and clone all unfinalized type arguments.
1683 // Finalized type arguments are shared. 1686 // Finalized type arguments are shared.
1684 RawTypeArguments* CloneUnfinalized() const; 1687 RawTypeArguments* CloneUnfinalized() const;
1685 1688
1686 // Clone this type argument vector and clone all uninstantiated type 1689 // Clone this type argument vector and clone all uninstantiated type
1687 // arguments, changing the class owner of type parameters. 1690 // arguments, changing the class owner of type parameters.
1688 // Instantiated type arguments are shared. 1691 // Instantiated type arguments are shared.
1689 RawTypeArguments* CloneUninstantiated(const Class& new_owner, 1692 RawTypeArguments* CloneUninstantiated(const Class& new_owner,
1690 TrailPtr trail = NULL) const; 1693 TrailPtr trail = NULL) const;
1691 1694
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
2214 2217
2215 // Return the type of this function's signature. It may not be canonical yet. 2218 // Return the type of this function's signature. It may not be canonical yet.
2216 // For example, if this function has a signature of the form 2219 // For example, if this function has a signature of the form
2217 // '(T, [B, C]) => R', where 'T' and 'R' are type parameters of the 2220 // '(T, [B, C]) => R', where 'T' and 'R' are type parameters of the
2218 // owner class of this function, then its signature type is a parameterized 2221 // owner class of this function, then its signature type is a parameterized
2219 // function type with uninstantiated type arguments 'T' and 'R' as elements of 2222 // function type with uninstantiated type arguments 'T' and 'R' as elements of
2220 // its type argument vector. 2223 // its type argument vector.
2221 RawType* SignatureType() const; 2224 RawType* SignatureType() const;
2222 RawType* ExistingSignatureType() const; 2225 RawType* ExistingSignatureType() const;
2223 2226
2224 // Allocate and return a signature function equivalent to this function.
2225 RawFunction* CanonicalSignatureFunction(TrailPtr trail) const;
2226
2227 // Update the signature type (with a canonical version). 2227 // Update the signature type (with a canonical version).
2228 void SetSignatureType(const Type& value) const; 2228 void SetSignatureType(const Type& value) const;
2229 2229
2230 // Return a new function with instantiated result and parameter types. 2230 // Return a new function with instantiated result and parameter types.
2231 RawFunction* InstantiateSignatureFrom( 2231 RawFunction* InstantiateSignatureFrom(
2232 const TypeArguments& instantiator_type_arguments, 2232 const TypeArguments& instantiator_type_arguments,
2233 const TypeArguments& function_type_arguments, 2233 const TypeArguments& function_type_arguments,
2234 Heap::Space space) const; 2234 Heap::Space space) const;
2235 2235
2236 // Build a string of the form '(T, {B b, C c}) => R' representing the 2236 // Build a string of the form '<T>(T, {B b, C c}) => R' representing the
2237 // internal signature of the given function. In this example, T and R are 2237 // internal signature of the given function. In this example, T is a type
2238 // type parameters of class C, the owner of the function. 2238 // parameter of this function and R is a type parameter of class C, the owner
2239 // of the function. B and C are not type parameters.
2239 RawString* Signature() const { return BuildSignature(kInternalName); } 2240 RawString* Signature() const { return BuildSignature(kInternalName); }
2240 2241
2241 // Build a string of the form '(T, {B b, C c}) => R' representing the 2242 // Build a string of the form '<T>(T, {B b, C c}) => R' representing the
2242 // user visible signature of the given function. In this example, T and R are 2243 // user visible signature of the given function. In this example, T is a type
2243 // type parameters of class C, the owner of the function. 2244 // parameter of this function and R is a type parameter of class C, the owner
2245 // of the function. B and C are not type parameters.
2244 // Implicit parameters are hidden. 2246 // Implicit parameters are hidden.
2245 RawString* UserVisibleSignature() const { 2247 RawString* UserVisibleSignature() const {
2246 return BuildSignature(kUserVisibleName); 2248 return BuildSignature(kUserVisibleName);
2247 } 2249 }
2248 2250
2249 // Returns true if the signature of this function is instantiated, i.e. if it 2251 // Returns true if the signature of this function is instantiated, i.e. if it
2250 // does not involve generic parameter types or generic result type. 2252 // does not involve generic parameter types or generic result type.
2253 // Note that function type parameters declared by this function do not make
2254 // its signature uninstantiated, only type parameters declared by parent
2255 // generic functions or class type parameters.
2251 bool HasInstantiatedSignature(Genericity genericity = kAny, 2256 bool HasInstantiatedSignature(Genericity genericity = kAny,
2252 intptr_t num_free_fun_type_params = kMaxInt32, 2257 intptr_t num_free_fun_type_params = kMaxInt32,
2253 TrailPtr trail = NULL) const; 2258 TrailPtr trail = NULL) const;
2254 2259
2255 // Build a string of the form 'T, {B b, C c}' representing the user 2260 // Build a string of the form 'T, {B b, C c}' representing the user
2256 // visible formal parameters of the function. 2261 // visible formal parameters of the function.
2257 RawString* UserVisibleFormalParameters() const; 2262 RawString* UserVisibleFormalParameters() const;
2258 2263
2259 // Reloading support: 2264 // Reloading support:
2260 void Reparent(const Class& new_cls) const; 2265 void Reparent(const Class& new_cls) const;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2301 return NumTypeParameters(Thread::Current()); 2306 return NumTypeParameters(Thread::Current());
2302 } 2307 }
2303 2308
2304 // Returns true if this function has the same number of type parameters with 2309 // Returns true if this function has the same number of type parameters with
2305 // equal bounds as the other function. Type parameter names are ignored. 2310 // equal bounds as the other function. Type parameter names are ignored.
2306 bool HasSameTypeParametersAndBounds(const Function& other) const; 2311 bool HasSameTypeParametersAndBounds(const Function& other) const;
2307 2312
2308 // Return the number of type parameters declared in parent generic functions. 2313 // Return the number of type parameters declared in parent generic functions.
2309 intptr_t NumParentTypeParameters() const; 2314 intptr_t NumParentTypeParameters() const;
2310 2315
2316 // Print the signature type of this function and of all of its parents.
2317 void PrintSignatureTypes() const;
2318
2311 // Return a TypeParameter if the type_name is a type parameter of this 2319 // Return a TypeParameter if the type_name is a type parameter of this
2312 // function or of one of its parent functions. 2320 // function or of one of its parent functions.
2313 // Unless NULL, adjust function_level accordingly (in and out parameter). 2321 // Unless NULL, adjust function_level accordingly (in and out parameter).
2314 // Return null otherwise. 2322 // Return null otherwise.
2315 RawTypeParameter* LookupTypeParameter(const String& type_name, 2323 RawTypeParameter* LookupTypeParameter(const String& type_name,
2316 intptr_t* function_level) const; 2324 intptr_t* function_level) const;
2317 2325
2318 // Return true if this function declares type parameters. 2326 // Return true if this function declares type parameters.
2319 bool IsGeneric() const { return NumTypeParameters(Thread::Current()) > 0; } 2327 bool IsGeneric() const { return NumTypeParameters(Thread::Current()) > 0; }
2320 2328
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
3053 Heap::Space space) const; 3061 Heap::Space space) const;
3054 3062
3055 FINAL_HEAP_OBJECT_IMPLEMENTATION(Function, Object); 3063 FINAL_HEAP_OBJECT_IMPLEMENTATION(Function, Object);
3056 friend class Class; 3064 friend class Class;
3057 friend class SnapshotWriter; 3065 friend class SnapshotWriter;
3058 friend class Parser; // For set_eval_script. 3066 friend class Parser; // For set_eval_script.
3059 // RawFunction::VisitFunctionPointers accesses the private constructor of 3067 // RawFunction::VisitFunctionPointers accesses the private constructor of
3060 // Function. 3068 // Function.
3061 friend class RawFunction; 3069 friend class RawFunction;
3062 friend class ClassFinalizer; // To reset parent_function. 3070 friend class ClassFinalizer; // To reset parent_function.
3071 friend class Type; // To adjust parent_function.
3063 }; 3072 };
3064 3073
3065 3074
3066 class ClosureData : public Object { 3075 class ClosureData : public Object {
3067 public: 3076 public:
3068 static intptr_t InstanceSize() { 3077 static intptr_t InstanceSize() {
3069 return RoundedAllocationSize(sizeof(RawClosureData)); 3078 return RoundedAllocationSize(sizeof(RawClosureData));
3070 } 3079 }
3071 3080
3072 private: 3081 private:
(...skipping 2659 matching lines...) Expand 10 before | Expand all | Expand 10 after
5732 TrailPtr trail = NULL) const; 5741 TrailPtr trail = NULL) const;
5733 virtual bool CanonicalizeEquals(const Instance& other) const { 5742 virtual bool CanonicalizeEquals(const Instance& other) const {
5734 return Equals(other); 5743 return Equals(other);
5735 } 5744 }
5736 virtual bool Equals(const Instance& other) const { 5745 virtual bool Equals(const Instance& other) const {
5737 return IsEquivalent(other); 5746 return IsEquivalent(other);
5738 } 5747 }
5739 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 5748 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
5740 virtual bool IsRecursive() const; 5749 virtual bool IsRecursive() const;
5741 5750
5751 // Set the scope of this type to the given function.
5752 virtual void SetScopeFunction(const Function& function) const;
5753
5742 // Check if this type represents a function type. 5754 // Check if this type represents a function type.
5743 virtual bool IsFunctionType() const { return false; } 5755 virtual bool IsFunctionType() const { return false; }
5744 5756
5745 // Instantiate this type using the given type argument vectors and possibly 5757 // Instantiate this type using the given type argument vectors and possibly
5746 // the current context. 5758 // the current context.
5747 // Return a new type, or return 'this' if it is already instantiated. 5759 // Return a new type, or return 'this' if it is already instantiated.
5748 // If bound_error is not NULL, it may be set to reflect a bound error. 5760 // If bound_error is not NULL, it may be set to reflect a bound error.
5749 virtual RawAbstractType* InstantiateFrom( 5761 virtual RawAbstractType* InstantiateFrom(
5750 const TypeArguments& instantiator_type_arguments, 5762 const TypeArguments& instantiator_type_arguments,
5751 const TypeArguments& function_type_arguments, 5763 const TypeArguments& function_type_arguments,
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
5947 void set_unresolved_class(const Object& value) const; 5959 void set_unresolved_class(const Object& value) const;
5948 virtual RawUnresolvedClass* unresolved_class() const; 5960 virtual RawUnresolvedClass* unresolved_class() const;
5949 virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; } 5961 virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; }
5950 virtual void set_arguments(const TypeArguments& value) const; 5962 virtual void set_arguments(const TypeArguments& value) const;
5951 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; } 5963 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; }
5952 virtual bool IsInstantiated(Genericity genericity = kAny, 5964 virtual bool IsInstantiated(Genericity genericity = kAny,
5953 intptr_t num_free_fun_type_params = kMaxInt32, 5965 intptr_t num_free_fun_type_params = kMaxInt32,
5954 TrailPtr trail = NULL) const; 5966 TrailPtr trail = NULL) const;
5955 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 5967 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
5956 virtual bool IsRecursive() const; 5968 virtual bool IsRecursive() const;
5969 virtual void SetScopeFunction(const Function& function) const;
5957 // If signature is not null, this type represents a function type. Note that 5970 // If signature is not null, this type represents a function type. Note that
5958 // the signature fully represents the type and type arguments can be ignored. 5971 // the signature fully represents the type and type arguments can be ignored.
5959 // However, in case of a generic typedef, they document how the typedef class 5972 // However, in case of a generic typedef, they document how the typedef class
5960 // was parameterized to obtain the actual signature. 5973 // was parameterized to obtain the actual signature.
5961 RawFunction* signature() const; 5974 RawFunction* signature() const;
5962 void set_signature(const Function& value) const; 5975 void set_signature(const Function& value) const;
5963 virtual bool IsFunctionType() const { 5976 virtual bool IsFunctionType() const {
5964 return signature() != Function::null(); 5977 return signature() != Function::null();
5965 } 5978 }
5966 virtual RawAbstractType* InstantiateFrom( 5979 virtual RawAbstractType* InstantiateFrom(
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
6097 return AbstractType::Handle(type()).arguments(); 6110 return AbstractType::Handle(type()).arguments();
6098 } 6111 }
6099 virtual TokenPosition token_pos() const { 6112 virtual TokenPosition token_pos() const {
6100 return AbstractType::Handle(type()).token_pos(); 6113 return AbstractType::Handle(type()).token_pos();
6101 } 6114 }
6102 virtual bool IsInstantiated(Genericity genericity = kAny, 6115 virtual bool IsInstantiated(Genericity genericity = kAny,
6103 intptr_t num_free_fun_type_params = kMaxInt32, 6116 intptr_t num_free_fun_type_params = kMaxInt32,
6104 TrailPtr trail = NULL) const; 6117 TrailPtr trail = NULL) const;
6105 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 6118 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
6106 virtual bool IsRecursive() const { return true; } 6119 virtual bool IsRecursive() const { return true; }
6120 virtual void SetScopeFunction(const Function& function) const;
6107 virtual RawTypeRef* InstantiateFrom( 6121 virtual RawTypeRef* InstantiateFrom(
6108 const TypeArguments& instantiator_type_arguments, 6122 const TypeArguments& instantiator_type_arguments,
6109 const TypeArguments& function_type_arguments, 6123 const TypeArguments& function_type_arguments,
6110 Error* bound_error, 6124 Error* bound_error,
6111 TrailPtr instantiation_trail, 6125 TrailPtr instantiation_trail,
6112 TrailPtr bound_trail, 6126 TrailPtr bound_trail,
6113 Heap::Space space) const; 6127 Heap::Space space) const;
6114 virtual RawTypeRef* CloneUninstantiated(const Class& new_owner, 6128 virtual RawTypeRef* CloneUninstantiated(const Class& new_owner,
6115 TrailPtr trail = NULL) const; 6129 TrailPtr trail = NULL) const;
6116 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const; 6130 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
6183 const AbstractType& upper_bound, 6197 const AbstractType& upper_bound,
6184 Error* bound_error, 6198 Error* bound_error,
6185 TrailPtr bound_trail, 6199 TrailPtr bound_trail,
6186 Heap::Space space) const; 6200 Heap::Space space) const;
6187 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; } 6201 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; }
6188 virtual bool IsInstantiated(Genericity genericity = kAny, 6202 virtual bool IsInstantiated(Genericity genericity = kAny,
6189 intptr_t num_free_fun_type_params = kMaxInt32, 6203 intptr_t num_free_fun_type_params = kMaxInt32,
6190 TrailPtr trail = NULL) const; 6204 TrailPtr trail = NULL) const;
6191 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 6205 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
6192 virtual bool IsRecursive() const { return false; } 6206 virtual bool IsRecursive() const { return false; }
6207 virtual void SetScopeFunction(const Function& function) const {}
6193 virtual RawAbstractType* InstantiateFrom( 6208 virtual RawAbstractType* InstantiateFrom(
6194 const TypeArguments& instantiator_type_arguments, 6209 const TypeArguments& instantiator_type_arguments,
6195 const TypeArguments& function_type_arguments, 6210 const TypeArguments& function_type_arguments,
6196 Error* bound_error, 6211 Error* bound_error,
6197 TrailPtr instantiation_trail, 6212 TrailPtr instantiation_trail,
6198 TrailPtr bound_trail, 6213 TrailPtr bound_trail,
6199 Heap::Space space) const; 6214 Heap::Space space) const;
6200 virtual RawAbstractType* CloneUnfinalized() const; 6215 virtual RawAbstractType* CloneUnfinalized() const;
6201 virtual RawAbstractType* CloneUninstantiated(const Class& new_owner, 6216 virtual RawAbstractType* CloneUninstantiated(const Class& new_owner,
6202 TrailPtr trail = NULL) const; 6217 TrailPtr trail = NULL) const;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
6285 TrailPtr trail = NULL) const { 6300 TrailPtr trail = NULL) const {
6286 // It is not possible to encounter an instantiated bounded type with an 6301 // It is not possible to encounter an instantiated bounded type with an
6287 // uninstantiated upper bound. Therefore, we do not need to check if the 6302 // uninstantiated upper bound. Therefore, we do not need to check if the
6288 // bound is instantiated. Moreover, doing so could lead into cycles, as in 6303 // bound is instantiated. Moreover, doing so could lead into cycles, as in
6289 // class C<T extends C<C>> { }. 6304 // class C<T extends C<C>> { }.
6290 return AbstractType::Handle(type()).IsInstantiated( 6305 return AbstractType::Handle(type()).IsInstantiated(
6291 genericity, num_free_fun_type_params, trail); 6306 genericity, num_free_fun_type_params, trail);
6292 } 6307 }
6293 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 6308 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
6294 virtual bool IsRecursive() const; 6309 virtual bool IsRecursive() const;
6310 virtual void SetScopeFunction(const Function& function) const;
6295 virtual RawAbstractType* InstantiateFrom( 6311 virtual RawAbstractType* InstantiateFrom(
6296 const TypeArguments& instantiator_type_arguments, 6312 const TypeArguments& instantiator_type_arguments,
6297 const TypeArguments& function_type_arguments, 6313 const TypeArguments& function_type_arguments,
6298 Error* bound_error, 6314 Error* bound_error,
6299 TrailPtr instantiation_trail, 6315 TrailPtr instantiation_trail,
6300 TrailPtr bound_trail, 6316 TrailPtr bound_trail,
6301 Heap::Space space) const; 6317 Heap::Space space) const;
6302 virtual RawAbstractType* CloneUnfinalized() const; 6318 virtual RawAbstractType* CloneUnfinalized() const;
6303 virtual RawAbstractType* CloneUninstantiated(const Class& new_owner, 6319 virtual RawAbstractType* CloneUninstantiated(const Class& new_owner,
6304 TrailPtr trail = NULL) const; 6320 TrailPtr trail = NULL) const;
(...skipping 2717 matching lines...) Expand 10 before | Expand all | Expand 10 after
9022 9038
9023 inline void TypeArguments::SetHash(intptr_t value) const { 9039 inline void TypeArguments::SetHash(intptr_t value) const {
9024 // This is only safe because we create a new Smi, which does not cause 9040 // This is only safe because we create a new Smi, which does not cause
9025 // heap allocation. 9041 // heap allocation.
9026 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); 9042 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
9027 } 9043 }
9028 9044
9029 } // namespace dart 9045 } // namespace dart
9030 9046
9031 #endif // RUNTIME_VM_OBJECT_H_ 9047 #endif // RUNTIME_VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698