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

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: address comments, move new test from language to language_2, sync 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
« no previous file with comments | « runtime/vm/clustered_snapshot.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 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 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 1666
1667 // Return true if all types of this vector are respectively, resolved, 1667 // Return true if all types of this vector are respectively, resolved,
1668 // finalized, or bounded. 1668 // finalized, or bounded.
1669 bool IsResolved() const; 1669 bool IsResolved() const;
1670 bool IsFinalized() const; 1670 bool IsFinalized() const;
1671 bool IsBounded() const; 1671 bool IsBounded() const;
1672 1672
1673 // Return true if this vector contains a recursive type argument. 1673 // Return true if this vector contains a recursive type argument.
1674 bool IsRecursive() const; 1674 bool IsRecursive() const;
1675 1675
1676 // Set the scope of this type argument vector to the given function.
1677 void SetScopeFunction(const Function& function) const;
1678
1676 // Clone this type argument vector and clone all unfinalized type arguments. 1679 // Clone this type argument vector and clone all unfinalized type arguments.
1677 // Finalized type arguments are shared. 1680 // Finalized type arguments are shared.
1678 RawTypeArguments* CloneUnfinalized() const; 1681 RawTypeArguments* CloneUnfinalized() const;
1679 1682
1680 // Clone this type argument vector and clone all uninstantiated type 1683 // Clone this type argument vector and clone all uninstantiated type
1681 // arguments, changing the class owner of type parameters. 1684 // arguments, changing the class owner of type parameters.
1682 // Instantiated type arguments are shared. 1685 // Instantiated type arguments are shared.
1683 RawTypeArguments* CloneUninstantiated(const Class& new_owner, 1686 RawTypeArguments* CloneUninstantiated(const Class& new_owner,
1684 TrailPtr trail = NULL) const; 1687 TrailPtr trail = NULL) const;
1685 1688
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
2203 2206
2204 // Return the type of this function's signature. It may not be canonical yet. 2207 // Return the type of this function's signature. It may not be canonical yet.
2205 // For example, if this function has a signature of the form 2208 // For example, if this function has a signature of the form
2206 // '(T, [B, C]) => R', where 'T' and 'R' are type parameters of the 2209 // '(T, [B, C]) => R', where 'T' and 'R' are type parameters of the
2207 // owner class of this function, then its signature type is a parameterized 2210 // owner class of this function, then its signature type is a parameterized
2208 // function type with uninstantiated type arguments 'T' and 'R' as elements of 2211 // function type with uninstantiated type arguments 'T' and 'R' as elements of
2209 // its type argument vector. 2212 // its type argument vector.
2210 RawType* SignatureType() const; 2213 RawType* SignatureType() const;
2211 RawType* ExistingSignatureType() const; 2214 RawType* ExistingSignatureType() const;
2212 2215
2213 // Allocate and return a signature function equivalent to this function.
2214 RawFunction* CanonicalSignatureFunction(TrailPtr trail) const;
2215
2216 // Update the signature type (with a canonical version). 2216 // Update the signature type (with a canonical version).
2217 void SetSignatureType(const Type& value) const; 2217 void SetSignatureType(const Type& value) const;
2218 2218
2219 // Return a new function with instantiated result and parameter types. 2219 // Return a new function with instantiated result and parameter types.
2220 RawFunction* InstantiateSignatureFrom( 2220 RawFunction* InstantiateSignatureFrom(
2221 const TypeArguments& instantiator_type_arguments, 2221 const TypeArguments& instantiator_type_arguments,
2222 const TypeArguments& function_type_arguments, 2222 const TypeArguments& function_type_arguments,
2223 Heap::Space space) const; 2223 Heap::Space space) const;
2224 2224
2225 // Build a string of the form '(T, {B b, C c}) => R' representing the 2225 // Build a string of the form '<T>(T, {B b, C c}) => R' representing the
2226 // internal signature of the given function. In this example, T and R are 2226 // internal signature of the given function. In this example, T is a type
2227 // type parameters of class C, the owner of the function. 2227 // parameter of this function and R is a type parameter of class C, the owner
2228 // of the function. B and C are not type parameters.
2228 RawString* Signature() const { return BuildSignature(kInternalName); } 2229 RawString* Signature() const { return BuildSignature(kInternalName); }
2229 2230
2230 // Build a string of the form '(T, {B b, C c}) => R' representing the 2231 // Build a string of the form '<T>(T, {B b, C c}) => R' representing the
2231 // user visible signature of the given function. In this example, T and R are 2232 // user visible signature of the given function. In this example, T is a type
2232 // type parameters of class C, the owner of the function. 2233 // parameter of this function and R is a type parameter of class C, the owner
2234 // of the function. B and C are not type parameters.
2233 // Implicit parameters are hidden. 2235 // Implicit parameters are hidden.
2234 RawString* UserVisibleSignature() const { 2236 RawString* UserVisibleSignature() const {
2235 return BuildSignature(kUserVisibleName); 2237 return BuildSignature(kUserVisibleName);
2236 } 2238 }
2237 2239
2238 // Returns true if the signature of this function is instantiated, i.e. if it 2240 // Returns true if the signature of this function is instantiated, i.e. if it
2239 // does not involve generic parameter types or generic result type. 2241 // does not involve generic parameter types or generic result type.
2242 // Note that function type parameters declared by this function do not make
2243 // its signature uninstantiated, only type parameters declared by parent
2244 // generic functions or class type parameters.
2240 bool HasInstantiatedSignature(Genericity genericity = kAny, 2245 bool HasInstantiatedSignature(Genericity genericity = kAny,
2241 intptr_t num_free_fun_type_params = kMaxInt32, 2246 intptr_t num_free_fun_type_params = kMaxInt32,
2242 TrailPtr trail = NULL) const; 2247 TrailPtr trail = NULL) const;
2243 2248
2244 // Build a string of the form 'T, {B b, C c}' representing the user 2249 // Build a string of the form 'T, {B b, C c}' representing the user
2245 // visible formal parameters of the function. 2250 // visible formal parameters of the function.
2246 RawString* UserVisibleFormalParameters() const; 2251 RawString* UserVisibleFormalParameters() const;
2247 2252
2248 // Reloading support: 2253 // Reloading support:
2249 void Reparent(const Class& new_cls) const; 2254 void Reparent(const Class& new_cls) const;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2290 return NumTypeParameters(Thread::Current()); 2295 return NumTypeParameters(Thread::Current());
2291 } 2296 }
2292 2297
2293 // Returns true if this function has the same number of type parameters with 2298 // Returns true if this function has the same number of type parameters with
2294 // equal bounds as the other function. Type parameter names are ignored. 2299 // equal bounds as the other function. Type parameter names are ignored.
2295 bool HasSameTypeParametersAndBounds(const Function& other) const; 2300 bool HasSameTypeParametersAndBounds(const Function& other) const;
2296 2301
2297 // Return the number of type parameters declared in parent generic functions. 2302 // Return the number of type parameters declared in parent generic functions.
2298 intptr_t NumParentTypeParameters() const; 2303 intptr_t NumParentTypeParameters() const;
2299 2304
2305 // Print the signature type of this function and of all of its parents.
2306 void PrintSignatureTypes() const;
2307
2300 // Return a TypeParameter if the type_name is a type parameter of this 2308 // Return a TypeParameter if the type_name is a type parameter of this
2301 // function or of one of its parent functions. 2309 // function or of one of its parent functions.
2302 // Unless NULL, adjust function_level accordingly (in and out parameter). 2310 // Unless NULL, adjust function_level accordingly (in and out parameter).
2303 // Return null otherwise. 2311 // Return null otherwise.
2304 RawTypeParameter* LookupTypeParameter(const String& type_name, 2312 RawTypeParameter* LookupTypeParameter(const String& type_name,
2305 intptr_t* function_level) const; 2313 intptr_t* function_level) const;
2306 2314
2307 // Return true if this function declares type parameters. 2315 // Return true if this function declares type parameters.
2308 bool IsGeneric() const { return NumTypeParameters(Thread::Current()) > 0; } 2316 bool IsGeneric() const { return NumTypeParameters(Thread::Current()) > 0; }
2309 2317
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
3042 Heap::Space space) const; 3050 Heap::Space space) const;
3043 3051
3044 FINAL_HEAP_OBJECT_IMPLEMENTATION(Function, Object); 3052 FINAL_HEAP_OBJECT_IMPLEMENTATION(Function, Object);
3045 friend class Class; 3053 friend class Class;
3046 friend class SnapshotWriter; 3054 friend class SnapshotWriter;
3047 friend class Parser; // For set_eval_script. 3055 friend class Parser; // For set_eval_script.
3048 // RawFunction::VisitFunctionPointers accesses the private constructor of 3056 // RawFunction::VisitFunctionPointers accesses the private constructor of
3049 // Function. 3057 // Function.
3050 friend class RawFunction; 3058 friend class RawFunction;
3051 friend class ClassFinalizer; // To reset parent_function. 3059 friend class ClassFinalizer; // To reset parent_function.
3060 friend class Type; // To adjust parent_function.
3052 }; 3061 };
3053 3062
3054 class ClosureData : public Object { 3063 class ClosureData : public Object {
3055 public: 3064 public:
3056 static intptr_t InstanceSize() { 3065 static intptr_t InstanceSize() {
3057 return RoundedAllocationSize(sizeof(RawClosureData)); 3066 return RoundedAllocationSize(sizeof(RawClosureData));
3058 } 3067 }
3059 3068
3060 private: 3069 private:
3061 RawContextScope* context_scope() const { return raw_ptr()->context_scope_; } 3070 RawContextScope* context_scope() const { return raw_ptr()->context_scope_; }
(...skipping 2619 matching lines...) Expand 10 before | Expand all | Expand 10 after
5681 TrailPtr trail = NULL) const; 5690 TrailPtr trail = NULL) const;
5682 virtual bool CanonicalizeEquals(const Instance& other) const { 5691 virtual bool CanonicalizeEquals(const Instance& other) const {
5683 return Equals(other); 5692 return Equals(other);
5684 } 5693 }
5685 virtual bool Equals(const Instance& other) const { 5694 virtual bool Equals(const Instance& other) const {
5686 return IsEquivalent(other); 5695 return IsEquivalent(other);
5687 } 5696 }
5688 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 5697 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
5689 virtual bool IsRecursive() const; 5698 virtual bool IsRecursive() const;
5690 5699
5700 // Set the scope of this type to the given function.
5701 virtual void SetScopeFunction(const Function& function) const;
5702
5691 // Check if this type represents a function type. 5703 // Check if this type represents a function type.
5692 virtual bool IsFunctionType() const { return false; } 5704 virtual bool IsFunctionType() const { return false; }
5693 5705
5694 // Instantiate this type using the given type argument vectors and possibly 5706 // Instantiate this type using the given type argument vectors and possibly
5695 // the current context. 5707 // the current context.
5696 // Return a new type, or return 'this' if it is already instantiated. 5708 // Return a new type, or return 'this' if it is already instantiated.
5697 // If bound_error is not NULL, it may be set to reflect a bound error. 5709 // If bound_error is not NULL, it may be set to reflect a bound error.
5698 virtual RawAbstractType* InstantiateFrom( 5710 virtual RawAbstractType* InstantiateFrom(
5699 const TypeArguments& instantiator_type_arguments, 5711 const TypeArguments& instantiator_type_arguments,
5700 const TypeArguments& function_type_arguments, 5712 const TypeArguments& function_type_arguments,
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
5895 void set_unresolved_class(const Object& value) const; 5907 void set_unresolved_class(const Object& value) const;
5896 virtual RawUnresolvedClass* unresolved_class() const; 5908 virtual RawUnresolvedClass* unresolved_class() const;
5897 virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; } 5909 virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; }
5898 virtual void set_arguments(const TypeArguments& value) const; 5910 virtual void set_arguments(const TypeArguments& value) const;
5899 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; } 5911 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; }
5900 virtual bool IsInstantiated(Genericity genericity = kAny, 5912 virtual bool IsInstantiated(Genericity genericity = kAny,
5901 intptr_t num_free_fun_type_params = kMaxInt32, 5913 intptr_t num_free_fun_type_params = kMaxInt32,
5902 TrailPtr trail = NULL) const; 5914 TrailPtr trail = NULL) const;
5903 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 5915 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
5904 virtual bool IsRecursive() const; 5916 virtual bool IsRecursive() const;
5917 virtual void SetScopeFunction(const Function& function) const;
5905 // If signature is not null, this type represents a function type. Note that 5918 // If signature is not null, this type represents a function type. Note that
5906 // the signature fully represents the type and type arguments can be ignored. 5919 // the signature fully represents the type and type arguments can be ignored.
5907 // However, in case of a generic typedef, they document how the typedef class 5920 // However, in case of a generic typedef, they document how the typedef class
5908 // was parameterized to obtain the actual signature. 5921 // was parameterized to obtain the actual signature.
5909 RawFunction* signature() const; 5922 RawFunction* signature() const;
5910 void set_signature(const Function& value) const; 5923 void set_signature(const Function& value) const;
5911 virtual bool IsFunctionType() const { 5924 virtual bool IsFunctionType() const {
5912 return signature() != Function::null(); 5925 return signature() != Function::null();
5913 } 5926 }
5914 virtual RawAbstractType* InstantiateFrom( 5927 virtual RawAbstractType* InstantiateFrom(
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
6044 return AbstractType::Handle(type()).arguments(); 6057 return AbstractType::Handle(type()).arguments();
6045 } 6058 }
6046 virtual TokenPosition token_pos() const { 6059 virtual TokenPosition token_pos() const {
6047 return AbstractType::Handle(type()).token_pos(); 6060 return AbstractType::Handle(type()).token_pos();
6048 } 6061 }
6049 virtual bool IsInstantiated(Genericity genericity = kAny, 6062 virtual bool IsInstantiated(Genericity genericity = kAny,
6050 intptr_t num_free_fun_type_params = kMaxInt32, 6063 intptr_t num_free_fun_type_params = kMaxInt32,
6051 TrailPtr trail = NULL) const; 6064 TrailPtr trail = NULL) const;
6052 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 6065 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
6053 virtual bool IsRecursive() const { return true; } 6066 virtual bool IsRecursive() const { return true; }
6067 virtual void SetScopeFunction(const Function& function) const;
6054 virtual RawTypeRef* InstantiateFrom( 6068 virtual RawTypeRef* InstantiateFrom(
6055 const TypeArguments& instantiator_type_arguments, 6069 const TypeArguments& instantiator_type_arguments,
6056 const TypeArguments& function_type_arguments, 6070 const TypeArguments& function_type_arguments,
6057 Error* bound_error, 6071 Error* bound_error,
6058 TrailPtr instantiation_trail, 6072 TrailPtr instantiation_trail,
6059 TrailPtr bound_trail, 6073 TrailPtr bound_trail,
6060 Heap::Space space) const; 6074 Heap::Space space) const;
6061 virtual RawTypeRef* CloneUninstantiated(const Class& new_owner, 6075 virtual RawTypeRef* CloneUninstantiated(const Class& new_owner,
6062 TrailPtr trail = NULL) const; 6076 TrailPtr trail = NULL) const;
6063 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const; 6077 virtual RawAbstractType* Canonicalize(TrailPtr trail = NULL) const;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
6129 const AbstractType& upper_bound, 6143 const AbstractType& upper_bound,
6130 Error* bound_error, 6144 Error* bound_error,
6131 TrailPtr bound_trail, 6145 TrailPtr bound_trail,
6132 Heap::Space space) const; 6146 Heap::Space space) const;
6133 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; } 6147 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; }
6134 virtual bool IsInstantiated(Genericity genericity = kAny, 6148 virtual bool IsInstantiated(Genericity genericity = kAny,
6135 intptr_t num_free_fun_type_params = kMaxInt32, 6149 intptr_t num_free_fun_type_params = kMaxInt32,
6136 TrailPtr trail = NULL) const; 6150 TrailPtr trail = NULL) const;
6137 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 6151 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
6138 virtual bool IsRecursive() const { return false; } 6152 virtual bool IsRecursive() const { return false; }
6153 virtual void SetScopeFunction(const Function& function) const {}
6139 virtual RawAbstractType* InstantiateFrom( 6154 virtual RawAbstractType* InstantiateFrom(
6140 const TypeArguments& instantiator_type_arguments, 6155 const TypeArguments& instantiator_type_arguments,
6141 const TypeArguments& function_type_arguments, 6156 const TypeArguments& function_type_arguments,
6142 Error* bound_error, 6157 Error* bound_error,
6143 TrailPtr instantiation_trail, 6158 TrailPtr instantiation_trail,
6144 TrailPtr bound_trail, 6159 TrailPtr bound_trail,
6145 Heap::Space space) const; 6160 Heap::Space space) const;
6146 virtual RawAbstractType* CloneUnfinalized() const; 6161 virtual RawAbstractType* CloneUnfinalized() const;
6147 virtual RawAbstractType* CloneUninstantiated(const Class& new_owner, 6162 virtual RawAbstractType* CloneUninstantiated(const Class& new_owner,
6148 TrailPtr trail = NULL) const; 6163 TrailPtr trail = NULL) const;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
6230 TrailPtr trail = NULL) const { 6245 TrailPtr trail = NULL) const {
6231 // It is not possible to encounter an instantiated bounded type with an 6246 // It is not possible to encounter an instantiated bounded type with an
6232 // uninstantiated upper bound. Therefore, we do not need to check if the 6247 // uninstantiated upper bound. Therefore, we do not need to check if the
6233 // bound is instantiated. Moreover, doing so could lead into cycles, as in 6248 // bound is instantiated. Moreover, doing so could lead into cycles, as in
6234 // class C<T extends C<C>> { }. 6249 // class C<T extends C<C>> { }.
6235 return AbstractType::Handle(type()).IsInstantiated( 6250 return AbstractType::Handle(type()).IsInstantiated(
6236 genericity, num_free_fun_type_params, trail); 6251 genericity, num_free_fun_type_params, trail);
6237 } 6252 }
6238 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 6253 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
6239 virtual bool IsRecursive() const; 6254 virtual bool IsRecursive() const;
6255 virtual void SetScopeFunction(const Function& function) const;
6240 virtual RawAbstractType* InstantiateFrom( 6256 virtual RawAbstractType* InstantiateFrom(
6241 const TypeArguments& instantiator_type_arguments, 6257 const TypeArguments& instantiator_type_arguments,
6242 const TypeArguments& function_type_arguments, 6258 const TypeArguments& function_type_arguments,
6243 Error* bound_error, 6259 Error* bound_error,
6244 TrailPtr instantiation_trail, 6260 TrailPtr instantiation_trail,
6245 TrailPtr bound_trail, 6261 TrailPtr bound_trail,
6246 Heap::Space space) const; 6262 Heap::Space space) const;
6247 virtual RawAbstractType* CloneUnfinalized() const; 6263 virtual RawAbstractType* CloneUnfinalized() const;
6248 virtual RawAbstractType* CloneUninstantiated(const Class& new_owner, 6264 virtual RawAbstractType* CloneUninstantiated(const Class& new_owner,
6249 TrailPtr trail = NULL) const; 6265 TrailPtr trail = NULL) const;
(...skipping 2663 matching lines...) Expand 10 before | Expand all | Expand 10 after
8913 8929
8914 inline void TypeArguments::SetHash(intptr_t value) const { 8930 inline void TypeArguments::SetHash(intptr_t value) const {
8915 // This is only safe because we create a new Smi, which does not cause 8931 // This is only safe because we create a new Smi, which does not cause
8916 // heap allocation. 8932 // heap allocation.
8917 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); 8933 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
8918 } 8934 }
8919 8935
8920 } // namespace dart 8936 } // namespace dart
8921 8937
8922 #endif // RUNTIME_VM_OBJECT_H_ 8938 #endif // RUNTIME_VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/clustered_snapshot.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698