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

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

Issue 2772803002: Revert "Use canonical names for some name-based lookup." (Closed)
Patch Set: Created 3 years, 9 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/kernel_reader.h ('k') | runtime/vm/kernel_to_il.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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/kernel_reader.h" 5 #include "vm/kernel_reader.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/longjump.h" 10 #include "vm/longjump.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 private: 78 private:
79 TranslationHelper translation_helper_; 79 TranslationHelper translation_helper_;
80 dart::Zone* zone_; 80 dart::Zone* zone_;
81 bool is_simple_; 81 bool is_simple_;
82 dart::Instance* simple_value_; 82 dart::Instance* simple_value_;
83 }; 83 };
84 84
85 85
86 RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary( 86 RawLibrary* BuildingTranslationHelper::LookupLibraryByKernelLibrary(
87 CanonicalName* library) { 87 Library* library) {
88 return reader_->LookupLibrary(library).raw(); 88 return reader_->LookupLibrary(library).raw();
89 } 89 }
90 90
91 91
92 RawClass* BuildingTranslationHelper::LookupClassByKernelClass( 92 RawClass* BuildingTranslationHelper::LookupClassByKernelClass(Class* klass) {
93 CanonicalName* klass) {
94 return reader_->LookupClass(klass).raw(); 93 return reader_->LookupClass(klass).raw();
95 } 94 }
96 95
97 KernelReader::KernelReader(Program* program) 96 KernelReader::KernelReader(Program* program)
98 : program_(program), 97 : program_(program),
99 thread_(dart::Thread::Current()), 98 thread_(dart::Thread::Current()),
100 zone_(thread_->zone()), 99 zone_(thread_->zone()),
101 isolate_(thread_->isolate()), 100 isolate_(thread_->isolate()),
102 scripts_(Array::ZoneHandle(zone_)), 101 scripts_(Array::ZoneHandle(zone_)),
103 translation_helper_(this, thread_), 102 translation_helper_(this, thread_),
104 type_translator_(&translation_helper_, 103 type_translator_(&translation_helper_,
105 &active_class_, 104 &active_class_,
106 /*finalize=*/false) { 105 /*finalize=*/false) {
107 intptr_t source_file_count = program_->source_table().size(); 106 intptr_t source_file_count = program_->source_table().size();
108 scripts_ = Array::New(source_file_count, Heap::kOld); 107 scripts_ = Array::New(source_file_count, Heap::kOld);
109 } 108 }
110 109
111 Object& KernelReader::ReadProgram() { 110 Object& KernelReader::ReadProgram() {
112 LongJumpScope jump; 111 LongJumpScope jump;
113 if (setjmp(*jump.Set()) == 0) { 112 if (setjmp(*jump.Set()) == 0) {
113 Procedure* main = program_->main_method();
114 Library* kernel_main_library = Library::Cast(main->parent());
115
114 intptr_t length = program_->libraries().length(); 116 intptr_t length = program_->libraries().length();
115 for (intptr_t i = 0; i < length; i++) { 117 for (intptr_t i = 0; i < length; i++) {
116 Library* kernel_library = program_->libraries()[i]; 118 Library* kernel_library = program_->libraries()[i];
117 ReadLibrary(kernel_library); 119 ReadLibrary(kernel_library);
118 } 120 }
119 121
120 for (intptr_t i = 0; i < length; i++) { 122 for (intptr_t i = 0; i < length; i++) {
121 dart::Library& library = 123 dart::Library& library = LookupLibrary(program_->libraries()[i]);
122 LookupLibrary(program_->libraries()[i]->canonical_name());
123 if (!library.Loaded()) library.SetLoaded(); 124 if (!library.Loaded()) library.SetLoaded();
124 } 125 }
125 126
126 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) { 127 if (ClassFinalizer::ProcessPendingClasses(/*from_kernel=*/true)) {
127 Procedure* main = program_->main_method(); 128 dart::Library& library = LookupLibrary(kernel_main_library);
128 Library* kernel_main_library = Library::Cast(main->parent());
129 dart::Library& library =
130 LookupLibrary(kernel_main_library->canonical_name());
131 129
132 // Sanity check that we can find the main entrypoint. 130 // Sanity check that we can find the main entrypoint.
133 Object& main_obj = Object::Handle( 131 Object& main_obj = Object::Handle(
134 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main"))); 132 Z, library.LookupObjectAllowPrivate(H.DartSymbol("main")));
135 ASSERT(!main_obj.IsNull()); 133 ASSERT(!main_obj.IsNull());
136 return library; 134 return library;
137 } 135 }
138 } 136 }
139 137
140 // Either class finalization failed or we caught a compile error. 138 // Either class finalization failed or we caught a compile error.
141 // In both cases sticky error would be set. 139 // In both cases sticky error would be set.
142 Error& error = Error::Handle(Z); 140 Error& error = Error::Handle(Z);
143 error = thread_->sticky_error(); 141 error = thread_->sticky_error();
144 thread_->clear_sticky_error(); 142 thread_->clear_sticky_error();
145 return error; 143 return error;
146 } 144 }
147 145
148 146
149 void KernelReader::ReadLibrary(Library* kernel_library) { 147 void KernelReader::ReadLibrary(Library* kernel_library) {
150 dart::Library& library = LookupLibrary(kernel_library->canonical_name()); 148 dart::Library& library = LookupLibrary(kernel_library);
151 if (library.Loaded()) return; 149 if (library.Loaded()) return;
152 150
153 // The bootstrapper will take care of creating the native wrapper classes, but 151 // The bootstrapper will take care of creating the native wrapper classes, but
154 // we will add the synthetic constructors to them here. 152 // we will add the synthetic constructors to them here.
155 if (library.name() == 153 if (library.name() ==
156 Symbols::Symbol(Symbols::kDartNativeWrappersLibNameId).raw()) { 154 Symbols::Symbol(Symbols::kDartNativeWrappersLibNameId).raw()) {
157 ASSERT(library.LoadInProgress()); 155 ASSERT(library.LoadInProgress());
158 } else { 156 } else {
159 library.SetLoadInProgress(); 157 library.SetLoadInProgress();
160 } 158 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 interfaces.SetAt(i, type); 276 interfaces.SetAt(i, type);
279 } 277 }
280 klass->set_interfaces(interfaces); 278 klass->set_interfaces(interfaces);
281 if (kernel_klass->is_abstract()) klass->set_is_abstract(); 279 if (kernel_klass->is_abstract()) klass->set_is_abstract();
282 } 280 }
283 281
284 282
285 dart::Class& KernelReader::ReadClass(const dart::Library& library, 283 dart::Class& KernelReader::ReadClass(const dart::Library& library,
286 const dart::Class& toplevel_class, 284 const dart::Class& toplevel_class,
287 Class* kernel_klass) { 285 Class* kernel_klass) {
288 dart::Class& klass = LookupClass(kernel_klass->canonical_name()); 286 // This will trigger a call to [ReadPreliminaryClass] if not already done.
289 287 dart::Class& klass = LookupClass(kernel_klass);
290 // The class needs to have a script because all the functions in the class
291 // will inherit it. The predicate Function::IsOptimizable uses the absence of
292 // a script to detect test functions that should not be optimized.
293 if (klass.script() == Script::null()) {
294 klass.set_script(ScriptAt(kernel_klass->source_uri_index()));
295 }
296 if (klass.token_pos() == TokenPosition::kNoSource) {
297 klass.set_token_pos(kernel_klass->position());
298 }
299 if (!klass.is_cycle_free()) {
300 ReadPreliminaryClass(&klass, kernel_klass);
301 }
302 288
303 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass); 289 ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass);
304 290
305 if (library.raw() == dart::Library::InternalLibrary() && 291 if (library.raw() == dart::Library::InternalLibrary() &&
306 klass.Name() == Symbols::ClassID().raw()) { 292 klass.Name() == Symbols::ClassID().raw()) {
307 // If this is a dart:internal.ClassID class ignore field declarations 293 // If this is a dart:internal.ClassID class ignore field declarations
308 // contained in the Kernel file and instead inject our own const 294 // contained in the Kernel file and instead inject our own const
309 // fields. 295 // fields.
310 klass.InjectCIDFields(); 296 klass.InjectCIDFields();
311 } else { 297 } else {
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 function.SetParameterNameAt(pos, Symbols::This()); 736 function.SetParameterNameAt(pos, Symbols::This());
751 pos++; 737 pos++;
752 } 738 }
753 if (is_setter) { 739 if (is_setter) {
754 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); 740 function.SetParameterTypeAt(pos, AbstractType::dynamic_type());
755 function.SetParameterNameAt(pos, Symbols::Value()); 741 function.SetParameterNameAt(pos, Symbols::Value());
756 pos++; 742 pos++;
757 } 743 }
758 } 744 }
759 745
760 dart::Library& KernelReader::LookupLibrary(CanonicalName* library) { 746 dart::Library& KernelReader::LookupLibrary(Library* library) {
761 dart::Library* handle = NULL; 747 dart::Library* handle = NULL;
762 if (!libraries_.Lookup(library, &handle)) { 748 if (!libraries_.Lookup(library, &handle)) {
763 const dart::String& url = H.DartSymbol(library->name()); 749 const dart::String& url = H.DartSymbol(library->import_uri());
764 handle = 750 handle =
765 &dart::Library::Handle(Z, dart::Library::LookupLibrary(thread_, url)); 751 &dart::Library::Handle(Z, dart::Library::LookupLibrary(thread_, url));
766 if (handle->IsNull()) { 752 if (handle->IsNull()) {
767 *handle = dart::Library::New(url); 753 *handle = dart::Library::New(url);
768 handle->Register(thread_); 754 handle->Register(thread_);
769 handle->SetName(H.DartSymbol(library->name())); 755 handle->SetName(H.DartSymbol(library->name()));
770 } 756 }
771 ASSERT(!handle->IsNull()); 757 ASSERT(!handle->IsNull());
772 libraries_.Insert(library, handle); 758 libraries_.Insert(library, handle);
773 } 759 }
774 return *handle; 760 return *handle;
775 } 761 }
776 762
777 dart::Class& KernelReader::LookupClass(CanonicalName* klass) { 763 dart::Class& KernelReader::LookupClass(Class* klass) {
778 dart::Class* handle = NULL; 764 dart::Class* handle = NULL;
779 if (!classes_.Lookup(klass, &handle)) { 765 if (!classes_.Lookup(klass, &handle)) {
780 dart::Library& library = LookupLibrary(klass->parent()); 766 dart::Library& library = LookupLibrary(klass->parent());
781 const dart::String& name = H.DartClassName(klass); 767 const dart::String& name = H.DartClassName(klass);
782 handle = &dart::Class::Handle(Z, library.LookupClass(name)); 768 handle = &dart::Class::Handle(Z, library.LookupClass(name));
783 if (handle->IsNull()) { 769 if (handle->IsNull()) {
784 *handle = dart::Class::New(library, name, Script::Handle(Z), 770 // The class needs to have a script because all the functions in the class
785 TokenPosition::kNoSource); 771 // will inherit it. The predicate Function::IsOptimizable uses the
772 // absence of a script to detect test functions that should not be
773 // optimized.
774 Script& script = ScriptAt(klass->source_uri_index());
775 handle = &dart::Class::Handle(
776 Z, dart::Class::New(library, name, script, klass->position()));
786 library.AddClass(*handle); 777 library.AddClass(*handle);
778 } else if (handle->script() == Script::null()) {
779 // When bootstrapping we can encounter classes that do not yet have a
780 // dummy script.
781 Script& script = ScriptAt(klass->source_uri_index());
782 handle->set_script(script);
787 } 783 }
788 // Insert the class in the cache before calling ReadPreliminaryClass so 784 // Insert the class in the cache before calling ReadPreliminaryClass so
789 // we do not risk allocating the class again by calling LookupClass 785 // we do not risk allocating the class again by calling LookupClass
790 // recursively from ReadPreliminaryClass for the same class. 786 // recursively from ReadPreliminaryClass for the same class.
791 classes_.Insert(klass, handle); 787 classes_.Insert(klass, handle);
788 if (!handle->is_cycle_free()) {
789 ReadPreliminaryClass(handle, klass);
790 }
792 } 791 }
793 return *handle; 792 return *handle;
794 } 793 }
795 794
796 795
797 RawFunction::Kind KernelReader::GetFunctionType(Procedure* kernel_procedure) { 796 RawFunction::Kind KernelReader::GetFunctionType(Procedure* kernel_procedure) {
798 intptr_t lookuptable[] = { 797 intptr_t lookuptable[] = {
799 RawFunction::kRegularFunction, // Procedure::kMethod 798 RawFunction::kRegularFunction, // Procedure::kMethod
800 RawFunction::kGetterFunction, // Procedure::kGetter 799 RawFunction::kGetterFunction, // Procedure::kGetter
801 RawFunction::kSetterFunction, // Procedure::kSetter 800 RawFunction::kSetterFunction, // Procedure::kSetter
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 initializer_fun.set_is_debuggable(false); 836 initializer_fun.set_is_debuggable(false);
838 initializer_fun.set_is_reflectable(false); 837 initializer_fun.set_is_reflectable(false);
839 initializer_fun.set_is_inlinable(false); 838 initializer_fun.set_is_inlinable(false);
840 return new (zone) ParsedFunction(thread, initializer_fun); 839 return new (zone) ParsedFunction(thread, initializer_fun);
841 } 840 }
842 841
843 842
844 } // namespace kernel 843 } // namespace kernel
845 } // namespace dart 844 } // namespace dart
846 #endif // !defined(DART_PRECOMPILED_RUNTIME) 845 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_reader.h ('k') | runtime/vm/kernel_to_il.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698