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

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

Issue 10942006: Fix bad optimization of instance-of with uninstantiated types (issue 5216). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
« no previous file with comments | « runtime/vm/intermediate_language.cc ('k') | tests/language/instanceof4_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 26 matching lines...) Expand all
37 37
38 DEFINE_FLAG(bool, generate_gdb_symbols, false, 38 DEFINE_FLAG(bool, generate_gdb_symbols, false,
39 "Generate symbols of generated dart functions for debugging with GDB"); 39 "Generate symbols of generated dart functions for debugging with GDB");
40 DEFINE_FLAG(bool, reject_named_argument_as_positional, false, 40 DEFINE_FLAG(bool, reject_named_argument_as_positional, false,
41 "Enforce new rules for optional parameters and disallow passing of named " 41 "Enforce new rules for optional parameters and disallow passing of named "
42 "arguments to optional positional formal parameters"); 42 "arguments to optional positional formal parameters");
43 DEFINE_FLAG(bool, show_internal_names, false, 43 DEFINE_FLAG(bool, show_internal_names, false,
44 "Show names of internal classes (e.g. \"OneByteString\") in error messages " 44 "Show names of internal classes (e.g. \"OneByteString\") in error messages "
45 "instead of showing the corresponding interface names (e.g. \"String\")"); 45 "instead of showing the corresponding interface names (e.g. \"String\")");
46 DECLARE_FLAG(bool, trace_compiler); 46 DECLARE_FLAG(bool, trace_compiler);
47 DECLARE_FLAG(bool, eliminate_type_checks);
47 DECLARE_FLAG(bool, enable_type_checks); 48 DECLARE_FLAG(bool, enable_type_checks);
48 49
49 static const char* kGetterPrefix = "get:"; 50 static const char* kGetterPrefix = "get:";
50 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); 51 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix);
51 static const char* kSetterPrefix = "set:"; 52 static const char* kSetterPrefix = "set:";
52 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix); 53 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix);
53 54
54 cpp_vtable Object::handle_vtable_ = 0; 55 cpp_vtable Object::handle_vtable_ = 0;
55 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 }; 56 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 };
56 cpp_vtable Smi::handle_vtable_ = 0; 57 cpp_vtable Smi::handle_vtable_ = 0;
(...skipping 8486 matching lines...) Expand 10 before | Expand all | Expand 10 after
8543 SetFieldAtOffset(field_offset, value); 8544 SetFieldAtOffset(field_offset, value);
8544 } 8545 }
8545 8546
8546 8547
8547 bool Instance::IsInstanceOf(const AbstractType& other, 8548 bool Instance::IsInstanceOf(const AbstractType& other,
8548 const AbstractTypeArguments& other_instantiator, 8549 const AbstractTypeArguments& other_instantiator,
8549 Error* malformed_error) const { 8550 Error* malformed_error) const {
8550 ASSERT(other.IsFinalized()); 8551 ASSERT(other.IsFinalized());
8551 ASSERT(!other.IsDynamicType()); 8552 ASSERT(!other.IsDynamicType());
8552 ASSERT(!other.IsMalformed()); 8553 ASSERT(!other.IsMalformed());
8553 if (IsNull()) { 8554 const Class& cls = Class::Handle(clazz());
8555 if (cls.IsNullClass()) {
8556 if (!IsNull()) {
8557 // We can only encounter Object::sentinel() or
8558 // Object::transition_sentinel() if type checks were not eliminated at
8559 // compile time. Both sentinels are instances of the Null class, but they
8560 // are not the Object::null() instance.
8561 ASSERT((raw() == Object::transition_sentinel()) ||
8562 (raw() == Object::sentinel()));
8563 ASSERT(!FLAG_eliminate_type_checks);
8564 return true; // We are doing an instance of test as part of a type check.
8565 }
8554 // The null instance can be returned from a void function. 8566 // The null instance can be returned from a void function.
8555 if (other.IsVoidType()) { 8567 if (other.IsVoidType()) {
8556 return true; 8568 return true;
8557 } 8569 }
8558 // Otherwise, null is only an instance of Object and of Dynamic. 8570 // Otherwise, null is only an instance of Object and of Dynamic.
8559 // It is not necessary to fully instantiate the other type for this test. 8571 // It is not necessary to fully instantiate the other type for this test.
8560 Class& other_class = Class::Handle(); 8572 Class& other_class = Class::Handle();
8561 if (other.IsTypeParameter()) { 8573 if (other.IsTypeParameter()) {
8562 if (other_instantiator.IsNull()) { 8574 if (other_instantiator.IsNull()) {
8563 return true; // Other type is uninstantiated, i.e. Dynamic. 8575 return true; // Other type is uninstantiated, i.e. Dynamic.
8564 } 8576 }
8565 const TypeParameter& other_type_param = TypeParameter::Cast(other); 8577 const TypeParameter& other_type_param = TypeParameter::Cast(other);
8566 const AbstractType& instantiated_other = AbstractType::Handle( 8578 const AbstractType& instantiated_other = AbstractType::Handle(
8567 other_instantiator.TypeAt(other_type_param.index())); 8579 other_instantiator.TypeAt(other_type_param.index()));
8568 ASSERT(instantiated_other.IsInstantiated()); 8580 ASSERT(instantiated_other.IsInstantiated());
8569 other_class = instantiated_other.type_class(); 8581 other_class = instantiated_other.type_class();
8570 } else { 8582 } else {
8571 other_class = other.type_class(); 8583 other_class = other.type_class();
8572 } 8584 }
8573 return other_class.IsObjectClass() || other_class.IsDynamicClass(); 8585 return other_class.IsObjectClass() || other_class.IsDynamicClass();
8574 } 8586 }
8575 if (other.IsVoidType()) { 8587 if (other.IsVoidType()) {
8576 return false; 8588 return false;
8577 } 8589 }
8578 const Class& cls = Class::Handle(clazz());
8579 // We must not encounter Object::sentinel() or Object::transition_sentinel(),
8580 // both instances of class NullClass, but not instance Object::null().
8581 ASSERT(!cls.IsNullClass());
8582 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); 8590 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle();
8583 const intptr_t num_type_arguments = cls.NumTypeArguments(); 8591 const intptr_t num_type_arguments = cls.NumTypeArguments();
8584 if (num_type_arguments > 0) { 8592 if (num_type_arguments > 0) {
8585 type_arguments = GetTypeArguments(); 8593 type_arguments = GetTypeArguments();
8586 if (!type_arguments.IsNull() && !type_arguments.IsCanonical()) { 8594 if (!type_arguments.IsNull() && !type_arguments.IsCanonical()) {
8587 type_arguments = type_arguments.Canonicalize(); 8595 type_arguments = type_arguments.Canonicalize();
8588 SetTypeArguments(type_arguments); 8596 SetTypeArguments(type_arguments);
8589 } 8597 }
8590 // Verify that the number of type arguments in the instance matches the 8598 // Verify that the number of type arguments in the instance matches the
8591 // number of type arguments expected by the instance class. 8599 // number of type arguments expected by the instance class.
(...skipping 3040 matching lines...) Expand 10 before | Expand all | Expand 10 after
11632 } 11640 }
11633 return result.raw(); 11641 return result.raw();
11634 } 11642 }
11635 11643
11636 11644
11637 const char* WeakProperty::ToCString() const { 11645 const char* WeakProperty::ToCString() const {
11638 return "_WeakProperty"; 11646 return "_WeakProperty";
11639 } 11647 }
11640 11648
11641 } // namespace dart 11649 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language.cc ('k') | tests/language/instanceof4_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698