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/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 self 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 // An object visitor which will iterate over all the function objects in the
75 // heap and check if the result type and parameter types are canonicalized
76 // or not. If they are not canonicalized if prints the function name out.
regis 2015/06/11 23:53:39 if -> it Actually, it does not print, it asserts,
siva 2015/06/12 00:23:14 Done.
77 class FunctionVisitor : public ObjectVisitor {
78 public:
79 explicit FunctionVisitor(Isolate* isolate) :
80 ObjectVisitor(isolate),
81 classHandle_(Class::Handle(isolate)),
82 funcHandle_(Function::Handle(isolate)),
83 typeHandle_(AbstractType::Handle(isolate)) {}
84
85 void VisitObject(RawObject* obj) {
86 if (obj->IsFunction()) {
87 funcHandle_ ^= obj;
88 classHandle_ ^= funcHandle_.Owner();
89 // Verify that the result type of a function is canonical or a
90 // TypeParameter.
91 typeHandle_ ^= funcHandle_.result_type();
92 ASSERT(typeHandle_.IsNull() ||
93 typeHandle_.IsTypeParameter() ||
94 typeHandle_.IsCanonical());
95 // Verify that the types in the function signature are all canonical or
96 // a TypeParameter
regis 2015/06/11 23:53:39 period
siva 2015/06/12 00:23:14 Done.
97 const intptr_t num_parameters = funcHandle_.NumParameters();
98 for (intptr_t i = 0; i < num_parameters; i++) {
99 typeHandle_ = funcHandle_.ParameterTypeAt(i);
100 ASSERT(typeHandle_.IsTypeParameter() || typeHandle_.IsCanonical());
101 }
102 }
103 }
104
105 private:
106 Class& classHandle_;
107 Function& funcHandle_;
108 AbstractType& typeHandle_;
109 };
110
111
74 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) { 112 static RawInstance* GetListInstance(Isolate* isolate, const Object& obj) {
75 if (obj.IsInstance()) { 113 if (obj.IsInstance()) {
76 const Library& core_lib = Library::Handle(Library::CoreLibrary()); 114 const Library& core_lib = Library::Handle(Library::CoreLibrary());
77 const Class& list_class = 115 const Class& list_class =
78 Class::Handle(core_lib.LookupClass(Symbols::List())); 116 Class::Handle(core_lib.LookupClass(Symbols::List()));
79 ASSERT(!list_class.IsNull()); 117 ASSERT(!list_class.IsNull());
80 const Instance& instance = Instance::Cast(obj); 118 const Instance& instance = Instance::Cast(obj);
81 const Class& obj_class = Class::Handle(isolate, obj.clazz()); 119 const Class& obj_class = Class::Handle(isolate, obj.clazz());
82 Error& malformed_type_error = Error::Handle(isolate); 120 Error& malformed_type_error = Error::Handle(isolate);
83 if (obj_class.IsSubtypeOf(Object::null_type_arguments(), 121 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); 1494 RETURN_NULL_ERROR(isolate_snapshot_buffer);
1457 } 1495 }
1458 if (isolate_snapshot_size == NULL) { 1496 if (isolate_snapshot_size == NULL) {
1459 RETURN_NULL_ERROR(isolate_snapshot_size); 1497 RETURN_NULL_ERROR(isolate_snapshot_size);
1460 } 1498 }
1461 // Finalize all classes if needed. 1499 // Finalize all classes if needed.
1462 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate); 1500 Dart_Handle state = Api::CheckAndFinalizePendingClasses(isolate);
1463 if (::Dart_IsError(state)) { 1501 if (::Dart_IsError(state)) {
1464 return state; 1502 return state;
1465 } 1503 }
1504 isolate->heap()->CollectAllGarbage();
1505 FunctionVisitor check_canonical(isolate);
1506 isolate->heap()->VisitObjects(&check_canonical);
regis 2015/06/11 23:53:39 The 2 lines above have no effect in release mode.
siva 2015/06/12 00:23:14 Yes I wrapped this under #if defined(DEBUG) ... #e
1507
1466 // Since this is only a snapshot the root library should not be set. 1508 // Since this is only a snapshot the root library should not be set.
1467 isolate->object_store()->set_root_library(Library::Handle(isolate)); 1509 isolate->object_store()->set_root_library(Library::Handle(isolate));
1468 FullSnapshotWriter writer(vm_isolate_snapshot_buffer, 1510 FullSnapshotWriter writer(vm_isolate_snapshot_buffer,
1469 isolate_snapshot_buffer, 1511 isolate_snapshot_buffer,
1470 ApiReallocate); 1512 ApiReallocate);
1471 writer.WriteFullSnapshot(); 1513 writer.WriteFullSnapshot();
1472 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); 1514 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
1473 *isolate_snapshot_size = writer.IsolateSnapshotSize(); 1515 *isolate_snapshot_size = writer.IsolateSnapshotSize();
1474 return Api::Success(); 1516 return Api::Success();
1475 } 1517 }
(...skipping 4130 matching lines...) Expand 10 before | Expand all | Expand 10 after
5606 5648
5607 5649
5608 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( 5650 DART_EXPORT void Dart_RegisterRootServiceRequestCallback(
5609 const char* name, 5651 const char* name,
5610 Dart_ServiceRequestCallback callback, 5652 Dart_ServiceRequestCallback callback,
5611 void* user_data) { 5653 void* user_data) {
5612 Service::RegisterRootEmbedderCallback(name, callback, user_data); 5654 Service::RegisterRootEmbedderCallback(name, callback, user_data);
5613 } 5655 }
5614 5656
5615 } // namespace dart 5657 } // 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