| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "vm/class_finalizer.h" | 5 #include "vm/class_finalizer.h" |
| 6 | 6 |
| 7 #include "vm/code_generator.h" | 7 #include "vm/code_generator.h" |
| 8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/hash_table.h" | 9 #include "vm/hash_table.h" |
| 10 #include "vm/heap.h" | 10 #include "vm/heap.h" |
| (...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 if (!super_type_arg.IsInstantiated()) { | 920 if (!super_type_arg.IsInstantiated()) { |
| 921 if (FLAG_trace_type_finalization && super_type_arg.IsTypeRef()) { | 921 if (FLAG_trace_type_finalization && super_type_arg.IsTypeRef()) { |
| 922 AbstractType& ref_type = | 922 AbstractType& ref_type = |
| 923 AbstractType::Handle(TypeRef::Cast(super_type_arg).type()); | 923 AbstractType::Handle(TypeRef::Cast(super_type_arg).type()); |
| 924 THR_Print( | 924 THR_Print( |
| 925 "Instantiating TypeRef '%s': '%s'\n" | 925 "Instantiating TypeRef '%s': '%s'\n" |
| 926 " instantiator: '%s'\n", | 926 " instantiator: '%s'\n", |
| 927 String::Handle(super_type_arg.Name()).ToCString(), | 927 String::Handle(super_type_arg.Name()).ToCString(), |
| 928 ref_type.ToCString(), arguments.ToCString()); | 928 ref_type.ToCString(), arguments.ToCString()); |
| 929 } | 929 } |
| 930 // In the typical case of an F-bounded type, the instantiation of the |
| 931 // super_type_arg from arguments is a fixpoint. Take the shortcut. |
| 932 // Example: class B<T>; class D<T> extends B<D<T>>; |
| 933 // While finalizing D<T>, the super type arg D<T> (a typeref) gets |
| 934 // instantiated from vector [T], yielding itself. |
| 935 // |
| 936 if (super_type_arg.IsTypeRef() && super_type_arg.IsBeingFinalized() && |
| 937 (super_type_arg.arguments() == arguments.raw())) { |
| 938 arguments.SetTypeAt(i, super_type_arg); |
| 939 continue; |
| 940 } |
| 930 Error& error = Error::Handle(); | 941 Error& error = Error::Handle(); |
| 931 super_type_arg = super_type_arg.InstantiateFrom( | 942 super_type_arg = super_type_arg.InstantiateFrom( |
| 932 arguments, &error, instantiation_trail, NULL, Heap::kOld); | 943 arguments, &error, instantiation_trail, NULL, Heap::kOld); |
| 933 if (!error.IsNull()) { | 944 if (!error.IsNull()) { |
| 934 // InstantiateFrom does not report an error if the type is still | 945 // InstantiateFrom does not report an error if the type is still |
| 935 // uninstantiated. Instead, it will return a new BoundedType so | 946 // uninstantiated. Instead, it will return a new BoundedType so |
| 936 // that the check is postponed to run time. | 947 // that the check is postponed to run time. |
| 937 ASSERT(super_type_arg.IsInstantiated()); | 948 ASSERT(super_type_arg.IsInstantiated()); |
| 938 // Keep only the first bound error. | 949 // Keep only the first bound error. |
| 939 if (bound_error->IsNull()) { | 950 if (bound_error->IsNull()) { |
| 940 *bound_error = error.raw(); | 951 *bound_error = error.raw(); |
| 941 } | 952 } |
| 942 } | 953 } |
| 943 if (!super_type_arg.IsFinalized() && | 954 if (super_type_arg.IsBeingFinalized()) { |
| 944 !super_type_arg.IsBeingFinalized()) { | |
| 945 // The super_type_arg was instantiated from a type being finalized. | 955 // The super_type_arg was instantiated from a type being finalized. |
| 946 // We need to finish finalizing its type arguments. | 956 // We need to finish finalizing its type arguments. |
| 947 if (super_type_arg.IsTypeRef()) { | 957 ASSERT(super_type_arg.IsTypeRef()); |
| 948 super_type_arg = TypeRef::Cast(super_type_arg).type(); | 958 AbstractType& ref_super_type_arg = |
| 949 } | 959 AbstractType::Handle(TypeRef::Cast(super_type_arg).type()); |
| 950 Type::Cast(super_type_arg).SetIsBeingFinalized(); | 960 ref_super_type_arg.SetIsFinalized(); |
| 951 pending_types->Add(super_type_arg); | 961 const Class& cls = Class::Handle(ref_super_type_arg.type_class()); |
| 952 const Class& cls = Class::Handle(super_type_arg.type_class()); | |
| 953 FinalizeTypeArguments( | 962 FinalizeTypeArguments( |
| 954 cls, TypeArguments::Handle(super_type_arg.arguments()), | 963 cls, TypeArguments::Handle(ref_super_type_arg.arguments()), |
| 955 cls.NumTypeArguments() - cls.NumTypeParameters(), bound_error, | 964 cls.NumTypeArguments() - cls.NumTypeParameters(), bound_error, |
| 956 pending_types, instantiation_trail); | 965 pending_types, instantiation_trail); |
| 957 Type::Cast(super_type_arg).SetIsFinalized(); | |
| 958 } | 966 } |
| 959 } | 967 } |
| 960 } | 968 } |
| 961 arguments.SetTypeAt(i, super_type_arg); | 969 arguments.SetTypeAt(i, super_type_arg); |
| 962 } | 970 } |
| 963 FinalizeTypeArguments(super_class, arguments, super_offset, bound_error, | 971 FinalizeTypeArguments(super_class, arguments, super_offset, bound_error, |
| 964 pending_types, instantiation_trail); | 972 pending_types, instantiation_trail); |
| 965 } | 973 } |
| 966 } | 974 } |
| 967 | 975 |
| (...skipping 2749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3717 ProgramVisitor::VisitFunctions(&function_visitor); | 3725 ProgramVisitor::VisitFunctions(&function_visitor); |
| 3718 | 3726 |
| 3719 class ClearCodeClassVisitor : public ClassVisitor { | 3727 class ClearCodeClassVisitor : public ClassVisitor { |
| 3720 void Visit(const Class& cls) { cls.DisableAllocationStub(); } | 3728 void Visit(const Class& cls) { cls.DisableAllocationStub(); } |
| 3721 }; | 3729 }; |
| 3722 ClearCodeClassVisitor class_visitor; | 3730 ClearCodeClassVisitor class_visitor; |
| 3723 ProgramVisitor::VisitClasses(&class_visitor); | 3731 ProgramVisitor::VisitClasses(&class_visitor); |
| 3724 } | 3732 } |
| 3725 | 3733 |
| 3726 } // namespace dart | 3734 } // namespace dart |
| OLD | NEW |