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

Side by Side Diff: runtime/lib/mirrors.cc

Issue 154393003: Implement eager instantiation and canonicalization of type arguments at run (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
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 #include "lib/invocation_mirror.h" 5 #include "lib/invocation_mirror.h"
6 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 ASSERT(!type.IsMalformed()); 849 ASSERT(!type.IsMalformed());
850 850
851 if (type.IsInstantiated()) { 851 if (type.IsInstantiated()) {
852 return type.Canonicalize(); 852 return type.Canonicalize();
853 } 853 }
854 854
855 ASSERT(!instantiator.IsNull()); 855 ASSERT(!instantiator.IsNull());
856 ASSERT(instantiator.IsFinalized()); 856 ASSERT(instantiator.IsFinalized());
857 ASSERT(!instantiator.IsMalformed()); 857 ASSERT(!instantiator.IsMalformed());
858 858
859 const AbstractTypeArguments& type_args = 859 const TypeArguments& type_args =
860 AbstractTypeArguments::Handle(instantiator.arguments()); 860 TypeArguments::Handle(instantiator.arguments());
861 Error& bound_error = Error::Handle(); 861 Error& bound_error = Error::Handle();
862 AbstractType& result = 862 AbstractType& result =
863 AbstractType::Handle(type.InstantiateFrom(type_args, &bound_error)); 863 AbstractType::Handle(type.InstantiateFrom(type_args, &bound_error));
864 if (!bound_error.IsNull()) { 864 if (!bound_error.IsNull()) {
865 ThrowInvokeError(bound_error); 865 ThrowInvokeError(bound_error);
866 UNREACHABLE(); 866 UNREACHABLE();
867 } 867 }
868 ASSERT(result.IsFinalized()); 868 ASSERT(result.IsFinalized());
869 return result.Canonicalize(); 869 return result.Canonicalize();
870 } 870 }
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 const Class& cls = Class::Handle(type.type_class()); 1251 const Class& cls = Class::Handle(type.type_class());
1252 const intptr_t num_params = cls.NumTypeParameters(); 1252 const intptr_t num_params = cls.NumTypeParameters();
1253 1253
1254 if (num_params == 0) { 1254 if (num_params == 0) {
1255 return Object::empty_array().raw(); 1255 return Object::empty_array().raw();
1256 } 1256 }
1257 1257
1258 const Array& result = Array::Handle(Array::New(num_params)); 1258 const Array& result = Array::Handle(Array::New(num_params));
1259 AbstractType& arg_type = AbstractType::Handle(); 1259 AbstractType& arg_type = AbstractType::Handle();
1260 Instance& type_mirror = Instance::Handle(); 1260 Instance& type_mirror = Instance::Handle();
1261 const AbstractTypeArguments& args = 1261 const TypeArguments& args = TypeArguments::Handle(type.arguments());
1262 AbstractTypeArguments::Handle(type.arguments());
1263 1262
1264 // Handle argument lists that have been optimized away, because either no 1263 // Handle argument lists that have been optimized away, because either no
1265 // arguments have been provided, or all arguments are dynamic. Return a list 1264 // arguments have been provided, or all arguments are dynamic. Return a list
1266 // of typemirrors on dynamic in this case. 1265 // of typemirrors on dynamic in this case.
1267 if (args.IsNull()) { 1266 if (args.IsNull()) {
1268 arg_type ^= Object::dynamic_type(); 1267 arg_type ^= Object::dynamic_type();
1269 type_mirror ^= CreateTypeMirror(arg_type); 1268 type_mirror ^= CreateTypeMirror(arg_type);
1270 for (intptr_t i = 0; i < num_params; i++) { 1269 for (intptr_t i = 0; i < num_params; i++) {
1271 result.SetAt(i, type_mirror); 1270 result.SetAt(i, type_mirror);
1272 } 1271 }
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 const Array& error_args = Array::Handle(Array::New(3)); 1742 const Array& error_args = Array::Handle(Array::New(3));
1744 error_args.SetAt(0, klass_name); 1743 error_args.SetAt(0, klass_name);
1745 // 1 = script url 1744 // 1 = script url
1746 // 2 = token position 1745 // 2 = token position
1747 Exceptions::ThrowByType(Exceptions::kAbstractClassInstantiation, 1746 Exceptions::ThrowByType(Exceptions::kAbstractClassInstantiation,
1748 error_args); 1747 error_args);
1749 UNREACHABLE(); 1748 UNREACHABLE();
1750 } 1749 }
1751 1750
1752 ASSERT(!type.IsNull()); 1751 ASSERT(!type.IsNull());
1753 AbstractTypeArguments& type_arguments = 1752 TypeArguments& type_arguments = TypeArguments::Handle(type.arguments());
1754 AbstractTypeArguments::Handle(type.arguments());
1755 if (!type.IsInstantiated()) { 1753 if (!type.IsInstantiated()) {
1756 // Must have been a declaration type. 1754 // Must have been a declaration type.
1757 AbstractType& rare_type = AbstractType::Handle(klass.RareType()); 1755 AbstractType& rare_type = AbstractType::Handle(klass.RareType());
1758 ASSERT(rare_type.IsInstantiated()); 1756 ASSERT(rare_type.IsInstantiated());
1759 type_arguments = rare_type.arguments(); 1757 type_arguments = rare_type.arguments();
1760 } 1758 }
1761 1759
1762 Class& redirected_klass = Class::Handle(klass.raw()); 1760 Class& redirected_klass = Class::Handle(klass.raw());
1763 Function& redirected_constructor = Function::Handle(lookup_constructor.raw()); 1761 Function& redirected_constructor = Function::Handle(lookup_constructor.raw());
1764 if (lookup_constructor.IsRedirectingFactory()) { 1762 if (lookup_constructor.IsRedirectingFactory()) {
1765 ClassFinalizer::ResolveRedirectingFactory(klass, lookup_constructor); 1763 ClassFinalizer::ResolveRedirectingFactory(klass, lookup_constructor);
1766 Type& redirect_type = Type::Handle(lookup_constructor.RedirectionType()); 1764 Type& redirect_type = Type::Handle(lookup_constructor.RedirectionType());
1767 1765
1768 if (!redirect_type.IsInstantiated()) { 1766 if (!redirect_type.IsInstantiated()) {
1769 // The type arguments of the redirection type are instantiated from the 1767 // The type arguments of the redirection type are instantiated from the
1770 // type arguments of the type reflected by the class mirror. 1768 // type arguments of the type reflected by the class mirror.
1771 Error& bound_error = Error::Handle(); 1769 Error& bound_error = Error::Handle();
1772 redirect_type ^= redirect_type.InstantiateFrom(type_arguments, 1770 redirect_type ^= redirect_type.InstantiateFrom(type_arguments,
1773 &bound_error); 1771 &bound_error);
1774 if (!bound_error.IsNull()) { 1772 if (!bound_error.IsNull()) {
1775 ThrowInvokeError(bound_error); 1773 ThrowInvokeError(bound_error);
1776 UNREACHABLE(); 1774 UNREACHABLE();
1777 } 1775 }
1776 redirect_type ^= redirect_type.Canonicalize();
1778 } 1777 }
1779 1778
1780 type = redirect_type.raw(); 1779 type = redirect_type.raw();
1781 type_arguments = redirect_type.arguments(); 1780 type_arguments = redirect_type.arguments();
1782 1781
1783 redirected_constructor = lookup_constructor.RedirectionTarget(); 1782 redirected_constructor = lookup_constructor.RedirectionTarget();
1784 ASSERT(!redirected_constructor.IsNull()); 1783 ASSERT(!redirected_constructor.IsNull());
1785 redirected_klass = type.type_class(); 1784 redirected_klass = type.type_class();
1786 } 1785 }
1787 1786
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 2088
2090 DEFINE_NATIVE_ENTRY(VariableMirror_type, 2) { 2089 DEFINE_NATIVE_ENTRY(VariableMirror_type, 2) {
2091 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 2090 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
2092 const Field& field = Field::Handle(ref.GetFieldReferent()); 2091 const Field& field = Field::Handle(ref.GetFieldReferent());
2093 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1)); 2092 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1));
2094 const AbstractType& type = AbstractType::Handle(field.type()); 2093 const AbstractType& type = AbstractType::Handle(field.type());
2095 return InstantiateType(type, instantiator); 2094 return InstantiateType(type, instantiator);
2096 } 2095 }
2097 2096
2098 } // namespace dart 2097 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/isolate.cc ('k') | runtime/lib/object.cc » ('j') | runtime/vm/code_generator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698