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

Side by Side Diff: runtime/vm/kernel_to_il.cc

Issue 2859673002: Pass type argument vector to generic functions (if --reify-generic-functions is (Closed)
Patch Set: Created 3 years, 7 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 #include <set> 5 #include <set>
6 6
7 #include "vm/kernel_to_il.h" 7 #include "vm/kernel_to_il.h"
8 8
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/intermediate_language.h" 10 #include "vm/intermediate_language.h"
(...skipping 1725 matching lines...) Expand 10 before | Expand all | Expand 10 after
1736 TypeArguments::Handle(Z, type_arguments.Canonicalize())); 1736 TypeArguments::Handle(Z, type_arguments.Canonicalize()));
1737 } 1737 }
1738 arg_values.SetAt(0, instance); 1738 arg_values.SetAt(0, instance);
1739 } else { 1739 } else {
1740 // Prepend type_arguments to list of arguments to factory. 1740 // Prepend type_arguments to list of arguments to factory.
1741 ASSERT(type_arguments.IsZoneHandle()); 1741 ASSERT(type_arguments.IsZoneHandle());
1742 arg_values.SetAt(0, type_arguments); 1742 arg_values.SetAt(0, type_arguments);
1743 } 1743 }
1744 arg_values.SetAt((0 + kNumExtraArgs), argument); 1744 arg_values.SetAt((0 + kNumExtraArgs), argument);
1745 const Array& args_descriptor = Array::Handle( 1745 const Array& args_descriptor = Array::Handle(
1746 Z, ArgumentsDescriptor::New(num_arguments, Object::empty_array())); 1746 Z, ArgumentsDescriptor::New(0, num_arguments, Object::empty_array()));
1747 const Object& result = Object::Handle( 1747 const Object& result = Object::Handle(
1748 Z, DartEntry::InvokeFunction(constructor, arg_values, args_descriptor)); 1748 Z, DartEntry::InvokeFunction(constructor, arg_values, args_descriptor));
1749 ASSERT(!result.IsError()); 1749 ASSERT(!result.IsError());
1750 if (constructor.IsFactory()) { 1750 if (constructor.IsFactory()) {
1751 // The factory method returns the allocated object. 1751 // The factory method returns the allocated object.
1752 instance ^= result.raw(); 1752 instance ^= result.raw();
1753 } 1753 }
1754 return H.Canonicalize(instance); 1754 return H.Canonicalize(instance);
1755 } 1755 }
1756 1756
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
2150 names.SetAt(i, H.DartSymbol(named_expression->name())); 2150 names.SetAt(i, H.DartSymbol(named_expression->name()));
2151 } 2151 }
2152 return RunFunction(function, arguments, names); 2152 return RunFunction(function, arguments, names);
2153 } 2153 }
2154 2154
2155 2155
2156 const Object& ConstantEvaluator::RunFunction(const Function& function, 2156 const Object& ConstantEvaluator::RunFunction(const Function& function,
2157 const Array& arguments, 2157 const Array& arguments,
2158 const Array& names) { 2158 const Array& names) {
2159 const Array& args_descriptor = 2159 const Array& args_descriptor =
2160 Array::Handle(Z, ArgumentsDescriptor::New(arguments.Length(), names)); 2160 Array::Handle(Z, ArgumentsDescriptor::New(0, arguments.Length(), names));
2161 const Object& result = Object::Handle( 2161 const Object& result = Object::Handle(
2162 Z, DartEntry::InvokeFunction(function, arguments, args_descriptor)); 2162 Z, DartEntry::InvokeFunction(function, arguments, args_descriptor));
2163 if (result.IsError()) { 2163 if (result.IsError()) {
2164 H.ReportError(Error::Cast(result), "error evaluating constant constructor"); 2164 H.ReportError(Error::Cast(result), "error evaluating constant constructor");
2165 } 2165 }
2166 return result; 2166 return result;
2167 } 2167 }
2168 2168
2169 2169
2170 FlowGraphBuilder::FlowGraphBuilder( 2170 FlowGraphBuilder::FlowGraphBuilder(
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
2668 } 2668 }
2669 2669
2670 2670
2671 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, 2671 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position,
2672 const dart::String& name, 2672 const dart::String& name,
2673 Token::Kind kind, 2673 Token::Kind kind,
2674 intptr_t argument_count, 2674 intptr_t argument_count,
2675 const Array& argument_names, 2675 const Array& argument_names,
2676 intptr_t num_args_checked) { 2676 intptr_t num_args_checked) {
2677 ArgumentArray arguments = GetArguments(argument_count); 2677 ArgumentArray arguments = GetArguments(argument_count);
2678 InstanceCallInstr* call = 2678 const intptr_t kTypeArgsLen = 0; // Generic instance calls not yet supported.
2679 new (Z) InstanceCallInstr(position, name, kind, arguments, argument_names, 2679 InstanceCallInstr* call = new (Z)
2680 num_args_checked, ic_data_array_); 2680 InstanceCallInstr(position, name, kind, arguments, kTypeArgsLen,
2681 argument_names, num_args_checked, ic_data_array_);
2681 Push(call); 2682 Push(call);
2682 return Fragment(call); 2683 return Fragment(call);
2683 } 2684 }
2684 2685
2685 2686
2686 Fragment FlowGraphBuilder::ClosureCall(int argument_count, 2687 Fragment FlowGraphBuilder::ClosureCall(int argument_count,
2687 const Array& argument_names) { 2688 const Array& argument_names) {
2688 Value* function = Pop(); 2689 Value* function = Pop();
2689 ArgumentArray arguments = GetArguments(argument_count); 2690 ArgumentArray arguments = GetArguments(argument_count);
2690 ClosureCallInstr* call = new (Z) ClosureCallInstr( 2691 const intptr_t kTypeArgsLen = 0; // Generic closures not yet supported.
2691 function, arguments, argument_names, TokenPosition::kNoSource); 2692 ClosureCallInstr* call =
2693 new (Z) ClosureCallInstr(function, arguments, kTypeArgsLen,
2694 argument_names, TokenPosition::kNoSource);
2692 Push(call); 2695 Push(call);
2693 return Fragment(call); 2696 return Fragment(call);
2694 } 2697 }
2695 2698
2696 2699
2697 Fragment FlowGraphBuilder::ThrowException(TokenPosition position) { 2700 Fragment FlowGraphBuilder::ThrowException(TokenPosition position) {
2698 Fragment instructions; 2701 Fragment instructions;
2699 instructions += Drop(); 2702 instructions += Drop();
2700 instructions += Fragment(new (Z) ThrowInstr(position)).closed(); 2703 instructions += Fragment(new (Z) ThrowInstr(position)).closed();
2701 // Use it's side effect of leaving a constant on the stack (does not change 2704 // Use it's side effect of leaving a constant on the stack (does not change
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2894 } 2897 }
2895 return FactoryRecognizer::ResultCid(function); 2898 return FactoryRecognizer::ResultCid(function);
2896 } 2899 }
2897 2900
2898 2901
2899 Fragment FlowGraphBuilder::StaticCall(TokenPosition position, 2902 Fragment FlowGraphBuilder::StaticCall(TokenPosition position,
2900 const Function& target, 2903 const Function& target,
2901 intptr_t argument_count, 2904 intptr_t argument_count,
2902 const Array& argument_names) { 2905 const Array& argument_names) {
2903 ArgumentArray arguments = GetArguments(argument_count); 2906 ArgumentArray arguments = GetArguments(argument_count);
2904 StaticCallInstr* call = new (Z) StaticCallInstr( 2907 const intptr_t kTypeArgsLen = 0; // Generic static calls not yet supported.
2905 position, target, argument_names, arguments, ic_data_array_); 2908 StaticCallInstr* call =
2909 new (Z) StaticCallInstr(position, target, kTypeArgsLen, argument_names,
2910 arguments, ic_data_array_);
2906 const intptr_t list_cid = 2911 const intptr_t list_cid =
2907 GetResultCidOfListFactory(Z, target, argument_count); 2912 GetResultCidOfListFactory(Z, target, argument_count);
2908 if (list_cid != kDynamicCid) { 2913 if (list_cid != kDynamicCid) {
2909 call->set_result_cid(list_cid); 2914 call->set_result_cid(list_cid);
2910 call->set_is_known_list_constructor(true); 2915 call->set_is_known_list_constructor(true);
2911 } else if (target.recognized_kind() != MethodRecognizer::kUnknown) { 2916 } else if (target.recognized_kind() != MethodRecognizer::kUnknown) {
2912 call->set_result_cid(MethodRecognizer::ResultCid(target)); 2917 call->set_result_cid(MethodRecognizer::ResultCid(target));
2913 } 2918 }
2914 Push(call); 2919 Push(call);
2915 return Fragment(call); 2920 return Fragment(call);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
3016 Fragment FlowGraphBuilder::StringInterpolate(TokenPosition position) { 3021 Fragment FlowGraphBuilder::StringInterpolate(TokenPosition position) {
3017 Value* array = Pop(); 3022 Value* array = Pop();
3018 StringInterpolateInstr* interpolate = 3023 StringInterpolateInstr* interpolate =
3019 new (Z) StringInterpolateInstr(array, position); 3024 new (Z) StringInterpolateInstr(array, position);
3020 Push(interpolate); 3025 Push(interpolate);
3021 return Fragment(interpolate); 3026 return Fragment(interpolate);
3022 } 3027 }
3023 3028
3024 3029
3025 Fragment FlowGraphBuilder::StringInterpolateSingle(TokenPosition position) { 3030 Fragment FlowGraphBuilder::StringInterpolateSingle(TokenPosition position) {
3031 const int kTypeArgsLen = 0;
3026 const int kNumberOfArguments = 1; 3032 const int kNumberOfArguments = 1;
3027 const Array& kNoArgumentNames = Object::null_array(); 3033 const Array& kNoArgumentNames = Object::null_array();
3028 const dart::Class& cls = dart::Class::Handle( 3034 const dart::Class& cls = dart::Class::Handle(
3029 dart::Library::LookupCoreClass(Symbols::StringBase())); 3035 dart::Library::LookupCoreClass(Symbols::StringBase()));
3030 ASSERT(!cls.IsNull()); 3036 ASSERT(!cls.IsNull());
3031 const Function& function = dart::Function::ZoneHandle( 3037 const Function& function = dart::Function::ZoneHandle(
3032 Z, dart::Resolver::ResolveStatic(cls, dart::Library::PrivateCoreLibName( 3038 Z,
3033 Symbols::InterpolateSingle()), 3039 dart::Resolver::ResolveStatic(
3034 kNumberOfArguments, kNoArgumentNames)); 3040 cls, dart::Library::PrivateCoreLibName(Symbols::InterpolateSingle()),
3041 kTypeArgsLen, kNumberOfArguments, kNoArgumentNames));
3035 Fragment instructions; 3042 Fragment instructions;
3036 instructions += PushArgument(); 3043 instructions += PushArgument();
3037 instructions += StaticCall(position, function, 1); 3044 instructions += StaticCall(position, function, 1);
3038 return instructions; 3045 return instructions;
3039 } 3046 }
3040 3047
3041 3048
3042 Fragment FlowGraphBuilder::ThrowTypeError() { 3049 Fragment FlowGraphBuilder::ThrowTypeError() {
3043 const dart::Class& klass = dart::Class::ZoneHandle( 3050 const dart::Class& klass = dart::Class::ZoneHandle(
3044 Z, dart::Library::LookupCoreClass(Symbols::TypeError())); 3051 Z, dart::Library::LookupCoreClass(Symbols::TypeError()));
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after
4228 Z, dart::Library::LookupCoreClass(Symbols::InvocationMirror())); 4235 Z, dart::Library::LookupCoreClass(Symbols::InvocationMirror()));
4229 ASSERT(!mirror_class.IsNull()); 4236 ASSERT(!mirror_class.IsNull());
4230 const Function& allocation_function = Function::ZoneHandle( 4237 const Function& allocation_function = Function::ZoneHandle(
4231 Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName( 4238 Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName(
4232 Symbols::AllocateInvocationMirror()))); 4239 Symbols::AllocateInvocationMirror())));
4233 ASSERT(!allocation_function.IsNull()); 4240 ASSERT(!allocation_function.IsNull());
4234 body += StaticCall(TokenPosition::kMinSource, allocation_function, 4); 4241 body += StaticCall(TokenPosition::kMinSource, allocation_function, 4);
4235 body += PushArgument(); // For the call to noSuchMethod. 4242 body += PushArgument(); // For the call to noSuchMethod.
4236 4243
4237 ArgumentsDescriptor two_arguments( 4244 ArgumentsDescriptor two_arguments(
4238 Array::Handle(Z, ArgumentsDescriptor::New(2))); 4245 Array::Handle(Z, ArgumentsDescriptor::New(0, 2)));
4239 Function& no_such_method = 4246 Function& no_such_method =
4240 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass( 4247 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass(
4241 dart::Class::Handle(Z, function.Owner()), 4248 dart::Class::Handle(Z, function.Owner()),
4242 Symbols::NoSuchMethod(), two_arguments)); 4249 Symbols::NoSuchMethod(), two_arguments));
4243 if (no_such_method.IsNull()) { 4250 if (no_such_method.IsNull()) {
4244 // If noSuchMethod is not found on the receiver class, call 4251 // If noSuchMethod is not found on the receiver class, call
4245 // Object.noSuchMethod. 4252 // Object.noSuchMethod.
4246 no_such_method = Resolver::ResolveDynamicForReceiverClass( 4253 no_such_method = Resolver::ResolveDynamicForReceiverClass(
4247 dart::Class::Handle(Z, I->object_store()->object_class()), 4254 dart::Class::Handle(Z, I->object_store()->object_class()),
4248 Symbols::NoSuchMethod(), two_arguments); 4255 Symbols::NoSuchMethod(), two_arguments);
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
5089 if (target.IsGenerativeConstructor() || target.IsFactory()) { 5096 if (target.IsGenerativeConstructor() || target.IsFactory()) {
5090 // The VM requires a TypeArguments object as first parameter for 5097 // The VM requires a TypeArguments object as first parameter for
5091 // every factory constructor. 5098 // every factory constructor.
5092 ++argument_count; 5099 ++argument_count;
5093 } 5100 }
5094 5101
5095 List<NamedExpression>& named = node->arguments()->named(); 5102 List<NamedExpression>& named = node->arguments()->named();
5096 const Array& argument_names = H.ArgumentNames(&named); 5103 const Array& argument_names = H.ArgumentNames(&named);
5097 5104
5098 // The frontend ensures we the [StaticInvocation] has matching arguments. 5105 // The frontend ensures we the [StaticInvocation] has matching arguments.
5099 ASSERT(target.AreValidArguments(argument_count, argument_names, NULL)); 5106 const intptr_t kTypeArgsLen = 0; // Generic functions not yet supported.
5107 ASSERT(target.AreValidArguments(kTypeArgsLen, argument_count, argument_names,
5108 NULL));
5100 5109
5101 Fragment instructions; 5110 Fragment instructions;
5102 LocalVariable* instance_variable = NULL; 5111 LocalVariable* instance_variable = NULL;
5103 5112
5104 // If we cross the Kernel -> VM core library boundary, a [StaticInvocation] 5113 // If we cross the Kernel -> VM core library boundary, a [StaticInvocation]
5105 // can appear, but the thing we're calling is not a static method, but a 5114 // can appear, but the thing we're calling is not a static method, but a
5106 // factory constructor. 5115 // factory constructor.
5107 // The `H.LookupStaticmethodByKernelProcedure` will potentially resolve to the 5116 // The `H.LookupStaticmethodByKernelProcedure` will potentially resolve to the
5108 // forwarded constructor. 5117 // forwarded constructor.
5109 // In that case we'll make an instance and pass it as first argument. 5118 // In that case we'll make an instance and pass it as first argument.
(...skipping 1733 matching lines...) Expand 10 before | Expand all | Expand 10 after
6843 thread->clear_sticky_error(); 6852 thread->clear_sticky_error();
6844 return error.raw(); 6853 return error.raw();
6845 } 6854 }
6846 } 6855 }
6847 6856
6848 6857
6849 } // namespace kernel 6858 } // namespace kernel
6850 } // namespace dart 6859 } // namespace dart
6851 6860
6852 #endif // !defined(DART_PRECOMPILED_RUNTIME) 6861 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698