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

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

Issue 2793033005: Keep types in signatures of function types properly instantiated as the function (Closed)
Patch Set: Created 3 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
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 2182 matching lines...) Expand 10 before | Expand all | Expand 10 after
2193 // For example, if this function has a signature of the form 2193 // For example, if this function has a signature of the form
2194 // '(T, [B, C]) => R', where 'T' and 'R' are type parameters of the 2194 // '(T, [B, C]) => R', where 'T' and 'R' are type parameters of the
2195 // owner class of this function, then its signature type is a parameterized 2195 // owner class of this function, then its signature type is a parameterized
2196 // function type with uninstantiated type arguments 'T' and 'R' as elements of 2196 // function type with uninstantiated type arguments 'T' and 'R' as elements of
2197 // its type argument vector. 2197 // its type argument vector.
2198 RawType* SignatureType() const; 2198 RawType* SignatureType() const;
2199 2199
2200 // Update the signature type (with a canonical version). 2200 // Update the signature type (with a canonical version).
2201 void SetSignatureType(const Type& value) const; 2201 void SetSignatureType(const Type& value) const;
2202 2202
2203 // Build a string of the form 'C<T, R>(T, {B b, C c}) => R' representing the 2203 // Return a new function with instantiated result and parameter types.
2204 RawFunction* InstantiateSignatureFrom(
2205 const TypeArguments& instantiator_type_arguments,
2206 Heap::Space space) const;
2207
2208 // Build a string of the form '(T, {B b, C c}) => R' representing the
2204 // internal signature of the given function. In this example, T and R are 2209 // internal signature of the given function. In this example, T and R are
2205 // type parameters of class C, the owner of the function. 2210 // type parameters of class C, the owner of the function.
2206 RawString* Signature() const { 2211 RawString* Signature() const { return BuildSignature(kInternalName); }
2207 const bool instantiate = false;
2208 return BuildSignature(instantiate, kInternalName,
2209 Object::null_type_arguments());
2210 }
2211 2212
2212 // Build a string of the form '(T, {B b, C c}) => R' representing the 2213 // Build a string of the form '(T, {B b, C c}) => R' representing the
2213 // user visible signature of the given function. In this example, T and R are 2214 // user visible signature of the given function. In this example, T and R are
2214 // type parameters of class C, the owner of the function, also called the 2215 // type parameters of class C, the owner of the function.
2215 // scope class of the function type. 2216 // Implicit parameters are hidden.
2216 // Implicit parameters are hidden, as well as the prefix denoting the
2217 // scope class and its type parameters.
2218 RawString* UserVisibleSignature() const { 2217 RawString* UserVisibleSignature() const {
2219 const bool instantiate = false; 2218 return BuildSignature(kUserVisibleName);
2220 return BuildSignature(instantiate, kUserVisibleName,
2221 Object::null_type_arguments());
2222 }
2223
2224 // Build a string of the form '(A, {B b, C c}) => D' representing the
2225 // signature of the given function, where all generic types (e.g. '<T, R>' in
2226 // 'C<T, R>(T, {B b, C c}) => R') are instantiated using the given
2227 // instantiator type argument vector of a C instance (e.g. '<A, D>').
2228 RawString* InstantiatedSignatureFrom(const TypeArguments& instantiator,
2229 NameVisibility name_visibility) const {
2230 const bool instantiate = true;
2231 return BuildSignature(instantiate, name_visibility, instantiator);
2232 } 2219 }
2233 2220
2234 // Returns true if the signature of this function is instantiated, i.e. if it 2221 // Returns true if the signature of this function is instantiated, i.e. if it
2235 // does not involve generic parameter types or generic result type. 2222 // does not involve generic parameter types or generic result type.
2236 bool HasInstantiatedSignature() const; 2223 bool HasInstantiatedSignature(Genericity genericity = kAny,
2224 TrailPtr trail = NULL) const;
2237 2225
2238 // Build a string of the form 'T, {B b, C c}' representing the user 2226 // Build a string of the form 'T, {B b, C c}' representing the user
2239 // visible formal parameters of the function. 2227 // visible formal parameters of the function.
2240 RawString* UserVisibleFormalParameters() const; 2228 RawString* UserVisibleFormalParameters() const;
2241 2229
2242 // Reloading support: 2230 // Reloading support:
2243 void Reparent(const Class& new_cls) const; 2231 void Reparent(const Class& new_cls) const;
2244 void ZeroEdgeCounters() const; 2232 void ZeroEdgeCounters() const;
2245 2233
2246 RawClass* Owner() const; 2234 RawClass* Owner() const;
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
2661 const char* ToQualifiedCString() const; 2649 const char* ToQualifiedCString() const;
2662 2650
2663 // Returns true if this function has parameters that are compatible with the 2651 // Returns true if this function has parameters that are compatible with the
2664 // parameters of the other function in order for this function to override the 2652 // parameters of the other function in order for this function to override the
2665 // other function. 2653 // other function.
2666 bool HasCompatibleParametersWith(const Function& other, 2654 bool HasCompatibleParametersWith(const Function& other,
2667 Error* bound_error) const; 2655 Error* bound_error) const;
2668 2656
2669 // Returns true if the type of this function is a subtype of the type of 2657 // Returns true if the type of this function is a subtype of the type of
2670 // the other function. 2658 // the other function.
2671 bool IsSubtypeOf(const TypeArguments& type_arguments, 2659 bool IsSubtypeOf(const Function& other,
2672 const Function& other,
2673 const TypeArguments& other_type_arguments,
2674 Error* bound_error, 2660 Error* bound_error,
2675 Heap::Space space) const { 2661 Heap::Space space) const {
2676 return TypeTest(kIsSubtypeOf, type_arguments, other, other_type_arguments, 2662 return TypeTest(kIsSubtypeOf, other, bound_error, space);
2677 bound_error, space);
2678 } 2663 }
2679 2664
2680 // Returns true if the type of this function is more specific than the type of 2665 // Returns true if the type of this function is more specific than the type of
2681 // the other function. 2666 // the other function.
2682 bool IsMoreSpecificThan(const TypeArguments& type_arguments, 2667 bool IsMoreSpecificThan(const Function& other,
2683 const Function& other,
2684 const TypeArguments& other_type_arguments,
2685 Error* bound_error, 2668 Error* bound_error,
2686 Heap::Space space) const { 2669 Heap::Space space) const {
2687 return TypeTest(kIsMoreSpecificThan, type_arguments, other, 2670 return TypeTest(kIsMoreSpecificThan, other, bound_error, space);
2688 other_type_arguments, bound_error, space);
2689 } 2671 }
2690 2672
2691 // Check the subtype or 'more specific' relationship. 2673 // Check the subtype or 'more specific' relationship.
2692 bool TypeTest(TypeTestKind test_kind, 2674 bool TypeTest(TypeTestKind test_kind,
2693 const TypeArguments& type_arguments,
2694 const Function& other, 2675 const Function& other,
2695 const TypeArguments& other_type_arguments,
2696 Error* bound_error, 2676 Error* bound_error,
2697 Heap::Space space) const; 2677 Heap::Space space) const;
2698 2678
2699 bool IsDispatcherOrImplicitAccessor() const { 2679 bool IsDispatcherOrImplicitAccessor() const {
2700 switch (kind()) { 2680 switch (kind()) {
2701 case RawFunction::kImplicitGetter: 2681 case RawFunction::kImplicitGetter:
2702 case RawFunction::kImplicitSetter: 2682 case RawFunction::kImplicitSetter:
2703 case RawFunction::kNoSuchMethodDispatcher: 2683 case RawFunction::kNoSuchMethodDispatcher:
2704 case RawFunction::kInvokeFieldDispatcher: 2684 case RawFunction::kInvokeFieldDispatcher:
2705 return true; 2685 return true;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2828 const Object& owner, 2808 const Object& owner,
2829 TokenPosition token_pos); 2809 TokenPosition token_pos);
2830 2810
2831 // Allocates a new Function object representing a closure function. 2811 // Allocates a new Function object representing a closure function.
2832 static RawFunction* NewClosureFunction(const String& name, 2812 static RawFunction* NewClosureFunction(const String& name,
2833 const Function& parent, 2813 const Function& parent,
2834 TokenPosition token_pos); 2814 TokenPosition token_pos);
2835 2815
2836 // Allocates a new Function object representing a signature function. 2816 // Allocates a new Function object representing a signature function.
2837 // The owner is the scope class of the function type. 2817 // The owner is the scope class of the function type.
2838 static RawFunction* NewSignatureFunction(const Class& owner, 2818 static RawFunction* NewSignatureFunction(const Object& owner,
2839 TokenPosition token_pos); 2819 TokenPosition token_pos);
2840 2820
2841 static RawFunction* NewEvalFunction(const Class& owner, 2821 static RawFunction* NewEvalFunction(const Class& owner,
2842 const Script& script, 2822 const Script& script,
2843 bool is_static); 2823 bool is_static);
2844 2824
2845 RawFunction* CreateMethodExtractor(const String& getter_name) const; 2825 RawFunction* CreateMethodExtractor(const String& getter_name) const;
2846 RawFunction* GetMethodExtractor(const String& getter_name) const; 2826 RawFunction* GetMethodExtractor(const String& getter_name) const;
2847 2827
2848 // Allocate new function object, clone values from this function. The 2828 // Allocate new function object, clone values from this function. The
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
3001 void set_kind_tag(uint32_t value) const; 2981 void set_kind_tag(uint32_t value) const;
3002 void set_data(const Object& value) const; 2982 void set_data(const Object& value) const;
3003 2983
3004 static RawFunction* New(); 2984 static RawFunction* New();
3005 2985
3006 RawString* QualifiedName(NameVisibility name_visibility) const; 2986 RawString* QualifiedName(NameVisibility name_visibility) const;
3007 2987
3008 void BuildSignatureParameters( 2988 void BuildSignatureParameters(
3009 Thread* thread, 2989 Thread* thread,
3010 Zone* zone, 2990 Zone* zone,
3011 bool instantiate,
3012 NameVisibility name_visibility, 2991 NameVisibility name_visibility,
3013 const TypeArguments& instantiator,
3014 GrowableHandlePtrArray<const String>* pieces) const; 2992 GrowableHandlePtrArray<const String>* pieces) const;
3015 RawString* BuildSignature(bool instantiate, 2993 RawString* BuildSignature(NameVisibility name_visibility) const;
3016 NameVisibility name_visibility,
3017 const TypeArguments& instantiator) const;
3018 2994
3019 // Checks the type of the formal parameter at the given position for 2995 // Checks the type of the formal parameter at the given position for
3020 // subtyping or 'more specific' relationship between the type of this function 2996 // subtyping or 'more specific' relationship between the type of this function
3021 // and the type of the other function. 2997 // and the type of the other function.
3022 bool TestParameterType(TypeTestKind test_kind, 2998 bool TestParameterType(TypeTestKind test_kind,
3023 intptr_t parameter_position, 2999 intptr_t parameter_position,
3024 intptr_t other_parameter_position, 3000 intptr_t other_parameter_position,
3025 const TypeArguments& type_arguments,
3026 const Function& other, 3001 const Function& other,
3027 const TypeArguments& other_type_arguments,
3028 Error* bound_error, 3002 Error* bound_error,
3029 Heap::Space space) const; 3003 Heap::Space space) const;
3030 3004
3031 FINAL_HEAP_OBJECT_IMPLEMENTATION(Function, Object); 3005 FINAL_HEAP_OBJECT_IMPLEMENTATION(Function, Object);
3032 friend class Class; 3006 friend class Class;
3033 friend class SnapshotWriter; 3007 friend class SnapshotWriter;
3034 friend class Parser; // For set_eval_script. 3008 friend class Parser; // For set_eval_script.
3035 // RawFunction::VisitFunctionPointers accesses the private constructor of 3009 // RawFunction::VisitFunctionPointers accesses the private constructor of
3036 // Function. 3010 // Function.
3037 friend class RawFunction; 3011 friend class RawFunction;
(...skipping 2885 matching lines...) Expand 10 before | Expand all | Expand 10 after
5923 void set_type_class(const Class& value) const; 5897 void set_type_class(const Class& value) const;
5924 void set_unresolved_class(const Object& value) const; 5898 void set_unresolved_class(const Object& value) const;
5925 virtual RawUnresolvedClass* unresolved_class() const; 5899 virtual RawUnresolvedClass* unresolved_class() const;
5926 virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; } 5900 virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; }
5927 virtual void set_arguments(const TypeArguments& value) const; 5901 virtual void set_arguments(const TypeArguments& value) const;
5928 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; } 5902 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; }
5929 virtual bool IsInstantiated(Genericity genericity = kAny, 5903 virtual bool IsInstantiated(Genericity genericity = kAny,
5930 TrailPtr trail = NULL) const; 5904 TrailPtr trail = NULL) const;
5931 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; 5905 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const;
5932 virtual bool IsRecursive() const; 5906 virtual bool IsRecursive() const;
5933 // If signature is not null, this type represents a function type. 5907 // If signature is not null, this type represents a function type. Note that
5908 // the signature fully represents the type and type arguments can be ignored.
5909 // However, in case of a generic typedef, they document how the typedef class
5910 // was parameterized to obtain the actual signature.
5934 RawFunction* signature() const; 5911 RawFunction* signature() const;
5935 void set_signature(const Function& value) const; 5912 void set_signature(const Function& value) const;
5936 virtual bool IsFunctionType() const { 5913 virtual bool IsFunctionType() const {
5937 return signature() != Function::null(); 5914 return signature() != Function::null();
5938 } 5915 }
5939 virtual RawAbstractType* InstantiateFrom( 5916 virtual RawAbstractType* InstantiateFrom(
5940 const TypeArguments& instantiator_type_arguments, 5917 const TypeArguments& instantiator_type_arguments,
5941 Error* bound_error, 5918 Error* bound_error,
5942 TrailPtr instantiation_trail, 5919 TrailPtr instantiation_trail,
5943 TrailPtr bound_trail, 5920 TrailPtr bound_trail,
(...skipping 3025 matching lines...) Expand 10 before | Expand all | Expand 10 after
8969 8946
8970 inline void TypeArguments::SetHash(intptr_t value) const { 8947 inline void TypeArguments::SetHash(intptr_t value) const {
8971 // This is only safe because we create a new Smi, which does not cause 8948 // This is only safe because we create a new Smi, which does not cause
8972 // heap allocation. 8949 // heap allocation.
8973 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); 8950 StoreSmi(&raw_ptr()->hash_, Smi::New(value));
8974 } 8951 }
8975 8952
8976 } // namespace dart 8953 } // namespace dart
8977 8954
8978 #endif // RUNTIME_VM_OBJECT_H_ 8955 #endif // RUNTIME_VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698