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

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

Issue 2799373002: Pass a second type argument vector to all type instantiation calls in the VM. (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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/code_patcher.h" 8 #include "vm/code_patcher.h"
9 #include "vm/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/heap.h" 10 #include "vm/heap.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 162 }
163 163
164 const TypeArguments& left_type_arguments = 164 const TypeArguments& left_type_arguments =
165 TypeArguments::Handle(left.GetTypeArguments()); 165 TypeArguments::Handle(left.GetTypeArguments());
166 const TypeArguments& right_type_arguments = 166 const TypeArguments& right_type_arguments =
167 TypeArguments::Handle(right.GetTypeArguments()); 167 TypeArguments::Handle(right.GetTypeArguments());
168 return Bool::Get(left_type_arguments.Equals(right_type_arguments)).raw(); 168 return Bool::Get(left_type_arguments.Equals(right_type_arguments)).raw();
169 } 169 }
170 170
171 171
172 DEFINE_NATIVE_ENTRY(Object_instanceOf, 3) { 172 DEFINE_NATIVE_ENTRY(Object_instanceOf, 4) {
173 const Instance& instance = 173 const Instance& instance =
174 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); 174 Instance::CheckedHandle(zone, arguments->NativeArgAt(0));
175 const TypeArguments& instantiator_type_arguments = 175 const TypeArguments& instantiator_type_arguments =
176 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); 176 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1));
177 const TypeArguments& function_type_arguments =
178 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(2));
177 const AbstractType& type = 179 const AbstractType& type =
178 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); 180 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(3));
179 ASSERT(type.IsFinalized()); 181 ASSERT(type.IsFinalized());
180 ASSERT(!type.IsMalformed()); 182 ASSERT(!type.IsMalformed());
181 ASSERT(!type.IsMalbounded()); 183 ASSERT(!type.IsMalbounded());
182 Error& bound_error = Error::Handle(zone, Error::null()); 184 Error& bound_error = Error::Handle(zone, Error::null());
183 const bool is_instance_of = 185 const bool is_instance_of = instance.IsInstanceOf(
184 instance.IsInstanceOf(type, instantiator_type_arguments, &bound_error); 186 type, instantiator_type_arguments, function_type_arguments, &bound_error);
185 if (FLAG_trace_type_checks) { 187 if (FLAG_trace_type_checks) {
186 const char* result_str = is_instance_of ? "true" : "false"; 188 const char* result_str = is_instance_of ? "true" : "false";
187 OS::Print("Native Object.instanceOf: result %s\n", result_str); 189 OS::Print("Native Object.instanceOf: result %s\n", result_str);
188 const AbstractType& instance_type = 190 const AbstractType& instance_type =
189 AbstractType::Handle(zone, instance.GetType(Heap::kNew)); 191 AbstractType::Handle(zone, instance.GetType(Heap::kNew));
190 OS::Print(" instance type: %s\n", 192 OS::Print(" instance type: %s\n",
191 String::Handle(zone, instance_type.Name()).ToCString()); 193 String::Handle(zone, instance_type.Name()).ToCString());
192 OS::Print(" test type: %s\n", 194 OS::Print(" test type: %s\n",
193 String::Handle(zone, type.Name()).ToCString()); 195 String::Handle(zone, type.Name()).ToCString());
194 if (!bound_error.IsNull()) { 196 if (!bound_error.IsNull()) {
(...skipping 16 matching lines...) Expand all
211 return Bool::Get(is_instance_of).raw(); 213 return Bool::Get(is_instance_of).raw();
212 } 214 }
213 215
214 DEFINE_NATIVE_ENTRY(Object_simpleInstanceOf, 2) { 216 DEFINE_NATIVE_ENTRY(Object_simpleInstanceOf, 2) {
215 // This native is only called when the right hand side passes 217 // This native is only called when the right hand side passes
216 // SimpleInstanceOfType and it is a non-negative test. 218 // SimpleInstanceOfType and it is a non-negative test.
217 const Instance& instance = 219 const Instance& instance =
218 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); 220 Instance::CheckedHandle(zone, arguments->NativeArgAt(0));
219 const AbstractType& type = 221 const AbstractType& type =
220 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(1)); 222 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(1));
221 const TypeArguments& instantiator_type_arguments = 223 const TypeArguments& null_type_arguments =
222 TypeArguments::Handle(TypeArguments::null()); 224 TypeArguments::Handle(TypeArguments::null());
223 ASSERT(type.IsFinalized()); 225 ASSERT(type.IsFinalized());
224 ASSERT(!type.IsMalformed()); 226 ASSERT(!type.IsMalformed());
225 ASSERT(!type.IsMalbounded()); 227 ASSERT(!type.IsMalbounded());
228 ASSERT(type.IsInstantiated());
226 Error& bound_error = Error::Handle(zone, Error::null()); 229 Error& bound_error = Error::Handle(zone, Error::null());
227 const bool is_instance_of = 230 const bool is_instance_of = instance.IsInstanceOf(
228 instance.IsInstanceOf(type, instantiator_type_arguments, &bound_error); 231 type, null_type_arguments, null_type_arguments, &bound_error);
siva 2017/04/10 22:04:55 ditto question about using Object::null_type_argum
regis 2017/04/11 04:23:07 Done.
229 if (!is_instance_of && !bound_error.IsNull()) { 232 if (!is_instance_of && !bound_error.IsNull()) {
230 // Throw a dynamic type error only if the instanceof test fails. 233 // Throw a dynamic type error only if the instanceof test fails.
231 DartFrameIterator iterator; 234 DartFrameIterator iterator;
232 StackFrame* caller_frame = iterator.NextFrame(); 235 StackFrame* caller_frame = iterator.NextFrame();
233 ASSERT(caller_frame != NULL); 236 ASSERT(caller_frame != NULL);
234 const TokenPosition location = caller_frame->GetTokenPos(); 237 const TokenPosition location = caller_frame->GetTokenPos();
235 String& bound_error_message = 238 String& bound_error_message =
236 String::Handle(zone, String::New(bound_error.ToErrorCString())); 239 String::Handle(zone, String::New(bound_error.ToErrorCString()));
237 Exceptions::CreateAndThrowTypeError(location, AbstractType::Handle(zone), 240 Exceptions::CreateAndThrowTypeError(location, AbstractType::Handle(zone),
238 AbstractType::Handle(zone), 241 AbstractType::Handle(zone),
239 Symbols::Empty(), bound_error_message); 242 Symbols::Empty(), bound_error_message);
240 UNREACHABLE(); 243 UNREACHABLE();
241 } 244 }
242 return Bool::Get(is_instance_of).raw(); 245 return Bool::Get(is_instance_of).raw();
243 } 246 }
244 247
245 248
246 DEFINE_NATIVE_ENTRY(Object_as, 3) { 249 DEFINE_NATIVE_ENTRY(Object_as, 4) {
247 const Instance& instance = 250 const Instance& instance =
248 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); 251 Instance::CheckedHandle(zone, arguments->NativeArgAt(0));
249 const TypeArguments& instantiator_type_arguments = 252 const TypeArguments& instantiator_type_arguments =
250 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); 253 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1));
254 const TypeArguments& function_type_arguments =
255 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(2));
251 AbstractType& type = 256 AbstractType& type =
252 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); 257 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(3));
253 ASSERT(type.IsFinalized()); 258 ASSERT(type.IsFinalized());
254 ASSERT(!type.IsMalformed()); 259 ASSERT(!type.IsMalformed());
255 ASSERT(!type.IsMalbounded()); 260 ASSERT(!type.IsMalbounded());
256 Error& bound_error = Error::Handle(zone); 261 Error& bound_error = Error::Handle(zone);
257 const bool is_instance_of = 262 const bool is_instance_of =
258 instance.IsNull() || 263 instance.IsNull() ||
259 instance.IsInstanceOf(type, instantiator_type_arguments, &bound_error); 264 instance.IsInstanceOf(type, instantiator_type_arguments,
265 function_type_arguments, &bound_error);
260 if (FLAG_trace_type_checks) { 266 if (FLAG_trace_type_checks) {
261 const char* result_str = is_instance_of ? "true" : "false"; 267 const char* result_str = is_instance_of ? "true" : "false";
262 OS::Print("Object.as: result %s\n", result_str); 268 OS::Print("Object.as: result %s\n", result_str);
263 const AbstractType& instance_type = 269 const AbstractType& instance_type =
264 AbstractType::Handle(zone, instance.GetType(Heap::kNew)); 270 AbstractType::Handle(zone, instance.GetType(Heap::kNew));
265 OS::Print(" instance type: %s\n", 271 OS::Print(" instance type: %s\n",
266 String::Handle(zone, instance_type.Name()).ToCString()); 272 String::Handle(zone, instance_type.Name()).ToCString());
267 OS::Print(" cast type: %s\n", 273 OS::Print(" cast type: %s\n",
268 String::Handle(zone, type.Name()).ToCString()); 274 String::Handle(zone, type.Name()).ToCString());
269 if (!bound_error.IsNull()) { 275 if (!bound_error.IsNull()) {
270 OS::Print(" bound error: %s\n", bound_error.ToErrorCString()); 276 OS::Print(" bound error: %s\n", bound_error.ToErrorCString());
271 } 277 }
272 } 278 }
273 if (!is_instance_of) { 279 if (!is_instance_of) {
274 DartFrameIterator iterator; 280 DartFrameIterator iterator;
275 StackFrame* caller_frame = iterator.NextFrame(); 281 StackFrame* caller_frame = iterator.NextFrame();
276 ASSERT(caller_frame != NULL); 282 ASSERT(caller_frame != NULL);
277 const TokenPosition location = caller_frame->GetTokenPos(); 283 const TokenPosition location = caller_frame->GetTokenPos();
278 const AbstractType& instance_type = 284 const AbstractType& instance_type =
279 AbstractType::Handle(zone, instance.GetType(Heap::kNew)); 285 AbstractType::Handle(zone, instance.GetType(Heap::kNew));
280 if (!type.IsInstantiated()) { 286 if (!type.IsInstantiated()) {
281 // Instantiate type before reporting the error. 287 // Instantiate type before reporting the error.
282 type = type.InstantiateFrom(instantiator_type_arguments, NULL, NULL, NULL, 288 type = type.InstantiateFrom(instantiator_type_arguments,
289 function_type_arguments, NULL, NULL, NULL,
283 Heap::kNew); 290 Heap::kNew);
284 // Note that the instantiated type may be malformed. 291 // Note that the instantiated type may be malformed.
285 } 292 }
286 if (bound_error.IsNull()) { 293 if (bound_error.IsNull()) {
287 Exceptions::CreateAndThrowTypeError(location, instance_type, type, 294 Exceptions::CreateAndThrowTypeError(location, instance_type, type,
288 Symbols::InTypeCast(), 295 Symbols::InTypeCast(),
289 Object::null_string()); 296 Object::null_string());
290 } else { 297 } else {
291 ASSERT(isolate->type_checks()); 298 ASSERT(isolate->type_checks());
292 const String& bound_error_message = 299 const String& bound_error_message =
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 352
346 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { 353 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) {
347 #if defined(ARCH_IS_64_BIT) 354 #if defined(ARCH_IS_64_BIT)
348 return Bool::True().raw(); 355 return Bool::True().raw();
349 #else 356 #else
350 return Bool::False().raw(); 357 return Bool::False().raw();
351 #endif // defined(ARCH_IS_64_BIT) 358 #endif // defined(ARCH_IS_64_BIT)
352 } 359 }
353 360
354 } // namespace dart 361 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698