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/intermediate_language.h" | 5 #include "vm/intermediate_language.h" |
6 | 6 |
7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
8 #include "vm/bootstrap.h" | 8 #include "vm/bootstrap.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/constant_propagator.h" | 10 #include "vm/constant_propagator.h" |
(...skipping 2047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2058 return this; | 2058 return this; |
2059 } | 2059 } |
2060 | 2060 |
2061 | 2061 |
2062 Definition* AssertAssignableInstr::Canonicalize(FlowGraph* flow_graph) { | 2062 Definition* AssertAssignableInstr::Canonicalize(FlowGraph* flow_graph) { |
2063 if (FLAG_eliminate_type_checks && | 2063 if (FLAG_eliminate_type_checks && |
2064 value()->Type()->IsAssignableTo(dst_type())) { | 2064 value()->Type()->IsAssignableTo(dst_type())) { |
2065 return value()->definition(); | 2065 return value()->definition(); |
2066 } | 2066 } |
2067 | 2067 |
2068 // For uninstantiated target types: If the instantiator type arguments | 2068 // For uninstantiated target types: If the instantiator and function |
2069 // are constant, instantiate the target type here. | 2069 // type arguments are constant, instantiate the target type here. |
2070 if (dst_type().IsInstantiated()) return this; | 2070 // If the uninstantiated type refers to parent function type parameters, we |
| 2071 // cannot instantiated it here. |
| 2072 if (dst_type().IsInstantiated() || |
| 2073 !dst_type().IsInstantiated(kParentFunctions)) { |
| 2074 return this; |
| 2075 } |
2071 | 2076 |
2072 // TODO(regis): Only try to instantiate here if function_type_args is constant | 2077 ConstantInstr* constant_instantiator_type_args = |
2073 // or null and dst_type does not refer to parent function type parameters. | |
2074 ConstantInstr* constant_type_args = | |
2075 instantiator_type_arguments()->definition()->AsConstant(); | 2078 instantiator_type_arguments()->definition()->AsConstant(); |
2076 if (constant_type_args != NULL) { | 2079 ConstantInstr* constant_function_type_args = |
2077 ASSERT(constant_type_args->value().IsNull() || | 2080 function_type_arguments()->definition()->AsConstant(); |
2078 constant_type_args->value().IsTypeArguments()); | 2081 if ((constant_instantiator_type_args != NULL) && |
| 2082 (constant_function_type_args != NULL)) { |
| 2083 ASSERT(constant_instantiator_type_args->value().IsNull() || |
| 2084 constant_instantiator_type_args->value().IsTypeArguments()); |
| 2085 ASSERT(constant_function_type_args->value().IsNull() || |
| 2086 constant_function_type_args->value().IsTypeArguments()); |
2079 TypeArguments& instantiator_type_args = TypeArguments::Handle(); | 2087 TypeArguments& instantiator_type_args = TypeArguments::Handle(); |
2080 instantiator_type_args ^= constant_type_args->value().raw(); | 2088 instantiator_type_args ^= constant_instantiator_type_args->value().raw(); |
| 2089 TypeArguments& function_type_args = TypeArguments::Handle(); |
| 2090 function_type_args ^= constant_function_type_args->value().raw(); |
2081 Error& bound_error = Error::Handle(); | 2091 Error& bound_error = Error::Handle(); |
2082 AbstractType& new_dst_type = | 2092 AbstractType& new_dst_type = AbstractType::Handle( |
2083 AbstractType::Handle(dst_type().InstantiateFrom( | 2093 dst_type().InstantiateFrom(instantiator_type_args, function_type_args, |
2084 instantiator_type_args, /* function_type_args, */ | 2094 &bound_error, NULL, NULL, Heap::kOld)); |
2085 &bound_error, NULL, NULL, Heap::kOld)); | |
2086 if (new_dst_type.IsMalformedOrMalbounded() || !bound_error.IsNull()) { | 2095 if (new_dst_type.IsMalformedOrMalbounded() || !bound_error.IsNull()) { |
2087 return this; | 2096 return this; |
2088 } | 2097 } |
2089 if (new_dst_type.IsTypeRef()) { | 2098 if (new_dst_type.IsTypeRef()) { |
2090 new_dst_type = TypeRef::Cast(new_dst_type).type(); | 2099 new_dst_type = TypeRef::Cast(new_dst_type).type(); |
2091 } | 2100 } |
2092 new_dst_type = new_dst_type.Canonicalize(); | 2101 new_dst_type = new_dst_type.Canonicalize(); |
2093 set_dst_type(new_dst_type); | 2102 set_dst_type(new_dst_type); |
2094 | 2103 |
2095 if (new_dst_type.IsDynamicType() || new_dst_type.IsObjectType() || | 2104 if (new_dst_type.IsDynamicType() || new_dst_type.IsObjectType() || |
2096 (FLAG_eliminate_type_checks && | 2105 (FLAG_eliminate_type_checks && |
2097 value()->Type()->IsAssignableTo(new_dst_type))) { | 2106 value()->Type()->IsAssignableTo(new_dst_type))) { |
2098 return value()->definition(); | 2107 return value()->definition(); |
2099 } | 2108 } |
2100 | 2109 |
2101 ConstantInstr* null_constant = flow_graph->constant_null(); | 2110 ConstantInstr* null_constant = flow_graph->constant_null(); |
2102 instantiator_type_arguments()->BindTo(null_constant); | 2111 instantiator_type_arguments()->BindTo(null_constant); |
2103 // TODO(regis): function_type_arguments()->BindTo(null_constant); | 2112 function_type_arguments()->BindTo(null_constant); |
2104 } | 2113 } |
2105 return this; | 2114 return this; |
2106 } | 2115 } |
2107 | 2116 |
2108 | 2117 |
2109 Definition* InstantiateTypeArgumentsInstr::Canonicalize(FlowGraph* flow_graph) { | 2118 Definition* InstantiateTypeArgumentsInstr::Canonicalize(FlowGraph* flow_graph) { |
2110 return (Isolate::Current()->type_checks() || HasUses()) ? this : NULL; | 2119 return (Isolate::Current()->type_checks() || HasUses()) ? this : NULL; |
2111 } | 2120 } |
2112 | 2121 |
2113 | 2122 |
(...skipping 1884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3998 "native function '%s' (%" Pd " arguments) cannot be found", | 4007 "native function '%s' (%" Pd " arguments) cannot be found", |
3999 native_name().ToCString(), function().NumParameters()); | 4008 native_name().ToCString(), function().NumParameters()); |
4000 } | 4009 } |
4001 set_is_auto_scope(auto_setup_scope); | 4010 set_is_auto_scope(auto_setup_scope); |
4002 set_native_c_function(native_function); | 4011 set_native_c_function(native_function); |
4003 } | 4012 } |
4004 | 4013 |
4005 #undef __ | 4014 #undef __ |
4006 | 4015 |
4007 } // namespace dart | 4016 } // namespace dart |
OLD | NEW |