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

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

Issue 1182673002: Add an assertion to ensure that the return type and types of parameters are canonical or a TypeParam (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address code review comments Created 5 years, 6 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
« no previous file with comments | « runtime/vm/compiler.cc ('k') | runtime/vm/raw_object.h » ('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) 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_mirrors_api.h" 6 #include "include/dart_mirrors_api.h"
7 #include "include/dart_native_api.h" 7 #include "include/dart_native_api.h"
8 8
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 const char* CanonicalFunction(const char* func) { 65 const char* CanonicalFunction(const char* func) {
66 if (strncmp(func, "dart::", 6) == 0) { 66 if (strncmp(func, "dart::", 6) == 0) {
67 return func + 6; 67 return func + 6;
68 } else { 68 } else {
69 return func; 69 return func;
70 } 70 }
71 } 71 }
72 72
73 73
74 #if defined(DEBUG)
75 // An object visitor which will iterate over all the function objects in the
76 // heap and check if the result type and parameter types are canonicalized
77 // or not. An assertion is raised if a type is not canonicalized.
78 class FunctionVisitor : public ObjectVisitor {
79 public:
80 explicit FunctionVisitor(Isolate* isolate) :
81 ObjectVisitor(isolate),
82 classHandle_(Class::Handle(isolate)),
83 funcHandle_(Function::Handle(isolate)),
84 typeHandle_(AbstractType::Handle(isolate)) {}
85
86 void VisitObject(RawObject* obj) {
87 if (obj->IsFunction()) {
88 funcHandle_ ^= obj;
89 classHandle_ ^= funcHandle_.Owner();
90 // Verify that the result type of a function is canonical or a
91 // TypeParameter.
92 typeHandle_ ^= funcHandle_.result_type();
93 ASSERT(typeHandle_.IsNull() ||
94 typeHandle_.IsTypeParameter() ||
95 typeHandle_.IsCanonical());
96 // Verify that the types in the function signature are all canonical or
97 // a TypeParameter.
98 const intptr_t num_parameters = funcHandle_.NumParameters();
99 for (intptr_t i = 0; i < num_parameters; i++) {
100 typeHandle_ = funcHandle_.ParameterTypeAt(i);
101 ASSERT(typeHandle_.IsTypeParameter() || typeHandle_.IsCanonical());
102 }
103 }
104 }
105
106 private:
107 Class& classHandle_;
108 Function& funcHandle_;
109 AbstractType& typeHandle_;
110 };
111 #endif // #if defined(DEBUG).
112
113
74 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { 114 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) {
75 if (obj.IsInstance()) { 115 if (obj.IsInstance()) {
76 const Library& core_lib = Library::Handle(Library::CoreLibrary()); 116 const Library& core_lib = Library::Handle(Library::CoreLibrary());
77 const Class& list_class = 117 const Class& list_class =
78 Class::Handle(core_lib.LookupClass(Symbols::List())); 118 Class::Handle(core_lib.LookupClass(Symbols::List()));
79 ASSERT(!list_class.IsNull()); 119 ASSERT(!list_class.IsNull());
80 const Instance& instance = Instance::Cast(obj); 120 const Instance& instance = Instance::Cast(obj);
81 const Class& obj_class = Class::Handle(isolate, obj.clazz()); 121 const Class& obj_class = Class::Handle(isolate, obj.clazz());
82 Error& malformed_type_error = Error::Handle(isolate); 122 Error& malformed_type_error = Error::Handle(isolate);
83 if (obj_class.IsSubtypeOf(Object::null_type_arguments(), 123 if (obj_class.IsSubtypeOf(Object::null_type_arguments(),
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 RETURN_NULL_ERROR(isolate_snapshot_buffer); 1496 RETURN_NULL_ERROR(isolate_snapshot_buffer);
1457 } 1497 }
1458 if (isolate_snapshot_size == NULL) { 1498 if (isolate_snapshot_size == NULL) {
1459 RETURN_NULL_ERROR(isolate_snapshot_size); 1499 RETURN_NULL_ERROR(isolate_snapshot_size);
1460 } 1500 }
1461 // Finalize all classes if needed. 1501 // Finalize all classes if needed.
1462 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); 1502 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate);
1463 if (::Dart_IsError(state)) { 1503 if (::Dart_IsError(state)) {
1464 return state; 1504 return state;
1465 } 1505 }
1506 isolate->heap()->CollectAllGarbage();
1507 #if defined(DEBUG)
1508 FunctionVisitor check_canonical(isolate);
1509 isolate->heap()->VisitObjects(&check_canonical);
1510 #endif // #if defined(DEBUG).
1511
1466 // Since this is only a snapshot the root library should not be set. 1512 // Since this is only a snapshot the root library should not be set.
1467 isolate->object_store()->set_root_library(Library::Handle(isolate)); 1513 isolate->object_store()->set_root_library(Library::Handle(isolate));
1468 FullSnapshotWriter writer(vm_isolate_snapshot_buffer, 1514 FullSnapshotWriter writer(vm_isolate_snapshot_buffer,
1469 isolate_snapshot_buffer, 1515 isolate_snapshot_buffer,
1470 ApiReallocate); 1516 ApiReallocate);
1471 writer.WriteFullSnapshot(); 1517 writer.WriteFullSnapshot();
1472 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); 1518 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
1473 *isolate_snapshot_size = writer.IsolateSnapshotSize(); 1519 *isolate_snapshot_size = writer.IsolateSnapshotSize();
1474 return Api::Success(); 1520 return Api::Success();
1475 } 1521 }
(...skipping 4130 matching lines...) Expand 10 before | Expand all | Expand 10 after
5606 5652
5607 5653
5608 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( 5654 DART_EXPORT void Dart_RegisterRootServiceRequestCallback(
5609 const char* name, 5655 const char* name,
5610 Dart_ServiceRequestCallback callback, 5656 Dart_ServiceRequestCallback callback,
5611 void* user_data) { 5657 void* user_data) {
5612 Service::RegisterRootEmbedderCallback(name, callback, user_data); 5658 Service::RegisterRootEmbedderCallback(name, callback, user_data);
5613 } 5659 }
5614 5660
5615 } // namespace dart 5661 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/compiler.cc ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698