From 1056c562aab6465bfcf31a2fe486e523a7e07554 Mon Sep 17 00:00:00 2001 From: Jens Johansen Date: Mon, 21 Nov 2016 11:16:29 +0100 Subject: [PATCH] Revert "Merge of source position information from kernel-sdk." The commit broke 2 tests: vm/cc/IsolateReload_TypeIdentityGeneric vm/cc/SourceReport_Coverage_AllFunctions_ForceCompile This reverts commit 6fd3a42edb4c7902a49811318de6bb6b18dbd829. BUG= Review URL: https://codereview.chromium.org/2517953002 . --- runtime/vm/bootstrap.cc | 5 +- runtime/vm/bootstrap_nocore.cc | 5 +- runtime/vm/exceptions.cc | 7 +- runtime/vm/kernel.h | 28 +++----- runtime/vm/kernel_binary.cc | 92 +++++++++++------------- runtime/vm/kernel_reader.cc | 95 +++++++++---------------- runtime/vm/kernel_reader.h | 14 ---- runtime/vm/kernel_to_il.cc | 125 ++++++++++++++------------------- runtime/vm/kernel_to_il.h | 15 ++-- runtime/vm/object.cc | 65 +++-------------- runtime/vm/object.h | 4 -- runtime/vm/raw_object.h | 2 - runtime/vm/symbols.h | 3 +- 13 files changed, 164 insertions(+), 296 deletions(-) diff --git a/runtime/vm/bootstrap.cc b/runtime/vm/bootstrap.cc index a354ddc4472b..5b4c20f115c8 100644 --- a/runtime/vm/bootstrap.cc +++ b/runtime/vm/bootstrap.cc @@ -321,8 +321,8 @@ static RawError* BootstrapFromKernel(Thread* thread, const uint8_t* buffer, intptr_t buffer_size) { Zone* zone = thread->zone(); - kernel::KernelReader reader(buffer, buffer_size, true); - kernel::Program* program = reader.ReadPrecompiledProgram(); + kernel::Program* program = + ReadPrecompiledKernelFromBuffer(buffer, buffer_size); if (program == NULL) { const String& message = String::Handle(zone, String::New("Failed to read Kernel file")); @@ -343,6 +343,7 @@ static RawError* BootstrapFromKernel(Thread* thread, Library& library = Library::Handle(zone); String& dart_name = String::Handle(zone); String& kernel_name = String::Handle(zone); + kernel::KernelReader reader(NULL, -1, true); for (intptr_t i = 0; i < kBootstrapLibraryCount; ++i) { ObjectStore::BootstrapLibraryId id = bootstrap_libraries[i].index; library = isolate->object_store()->bootstrap_library(id); diff --git a/runtime/vm/bootstrap_nocore.cc b/runtime/vm/bootstrap_nocore.cc index 9fda4b3a6cdb..d804b2484ec2 100644 --- a/runtime/vm/bootstrap_nocore.cc +++ b/runtime/vm/bootstrap_nocore.cc @@ -59,8 +59,8 @@ RawError* BootstrapFromKernel(Thread* thread, const uint8_t* buffer, intptr_t buffer_length) { Zone* zone = thread->zone(); - kernel::KernelReader reader(buffer, buffer_length, true); - kernel::Program* program = reader.ReadPrecompiledProgram(); + kernel::Program* program = + ReadPrecompiledKernelFromBuffer(buffer, buffer_length); if (program == NULL) { const String& message = String::Handle(zone, String::New("Failed to read Kernel file")); @@ -81,6 +81,7 @@ RawError* BootstrapFromKernel(Thread* thread, Library& library = Library::Handle(zone); String& dart_name = String::Handle(zone); String& kernel_name = String::Handle(zone); + kernel::KernelReader reader(NULL, -1, true); for (intptr_t i = 0; i < bootstrap_library_count; ++i) { ObjectStore::BootstrapLibraryId id = bootstrap_libraries[i].index; library = isolate->object_store()->bootstrap_library(id); diff --git a/runtime/vm/exceptions.cc b/runtime/vm/exceptions.cc index 537b97fdaddd..db0d71024c03 100644 --- a/runtime/vm/exceptions.cc +++ b/runtime/vm/exceptions.cc @@ -506,11 +506,12 @@ void Exceptions::CreateAndThrowTypeError(TokenPosition location, DartFrameIterator iterator; const Script& script = Script::Handle(zone, GetCallerScript(&iterator)); - intptr_t line = -1; + intptr_t line; intptr_t column = -1; - ASSERT(!script.IsNull()); - if (location.IsReal()) { + if (script.HasSource()) { script.GetTokenLocation(location, &line, &column); + } else { + script.GetTokenLocation(location, &line, NULL); } // Initialize '_url', '_line', and '_column' arguments. args.SetAt(0, String::Handle(zone, script.url())); diff --git a/runtime/vm/kernel.h b/runtime/vm/kernel.h index 8e969411f5b0..93b828baf7b1 100644 --- a/runtime/vm/kernel.h +++ b/runtime/vm/kernel.h @@ -9,7 +9,6 @@ #include "platform/assert.h" #include "vm/allocation.h" #include "vm/globals.h" -#include "vm/token_position.h" #define KERNEL_NODES_DO(M) \ @@ -309,7 +308,7 @@ class StringTable { class LineStartingTable { public: - void ReadFrom(Reader* reader); + void ReadFrom(Reader* reader, intptr_t length); void WriteTo(Writer* writer); ~LineStartingTable() { for (intptr_t i = 0; i < size_; ++i) { @@ -414,7 +413,6 @@ class Library : public TreeNode { virtual void VisitChildren(Visitor* visitor); String* import_uri() { return import_uri_; } - intptr_t source_uri_index() { return source_uri_index_; } String* name() { return name_; } List& classes() { return classes_; } List& fields() { return fields_; } @@ -450,7 +448,6 @@ class Library : public TreeNode { Ref name_; Ref import_uri_; - intptr_t source_uri_index_; List classes_; List fields_; List procedures_; @@ -474,7 +471,6 @@ class Class : public TreeNode { Library* parent() { return parent_; } String* name() { return name_; } - intptr_t source_uri_index() { return source_uri_index_; } bool is_abstract() { return is_abstract_; } List& annotations() { return annotations_; } @@ -493,7 +489,6 @@ class Class : public TreeNode { Ref parent_; Ref name_; - intptr_t source_uri_index_; bool is_abstract_; List annotations_; @@ -634,25 +629,21 @@ class Field : public Member { bool IsConst() { return (flags_ & kFlagConst) == kFlagConst; } bool IsFinal() { return (flags_ & kFlagFinal) == kFlagFinal; } bool IsStatic() { return (flags_ & kFlagStatic) == kFlagStatic; } - intptr_t source_uri_index() { return source_uri_index_; } DartType* type() { return type_; } InferredValue* inferred_value() { return inferred_value_; } Expression* initializer() { return initializer_; } - TokenPosition position() { return position_; } private: - Field() : position_(TokenPosition::kNoSource) {} + Field() {} template friend class List; word flags_; - intptr_t source_uri_index_; Child type_; Child inferred_value_; Child initializer_; - TokenPosition position_; DISALLOW_COPY_AND_ASSIGN(Field); }; @@ -734,7 +725,6 @@ class Procedure : public Member { bool IsAbstract() { return (flags_ & kFlagAbstract) == kFlagAbstract; } bool IsExternal() { return (flags_ & kFlagExternal) == kFlagExternal; } bool IsConst() { return (flags_ & kFlagConst) == kFlagConst; } - intptr_t source_uri_index() { return source_uri_index_; } private: Procedure() : kind_(kIncompleteProcedure), flags_(0), function_(NULL) {} @@ -744,7 +734,6 @@ class Procedure : public Member { ProcedureKind kind_; word flags_; - intptr_t source_uri_index_; Child function_; DISALLOW_COPY_AND_ASSIGN(Procedure); @@ -945,11 +934,9 @@ class Expression : public TreeNode { virtual void AcceptTreeVisitor(TreeVisitor* visitor); virtual void AcceptExpressionVisitor(ExpressionVisitor* visitor) = 0; - TokenPosition position() { return position_; } protected: - Expression() : position_(TokenPosition::kNoSource) {} - TokenPosition position_; + Expression() {} private: DISALLOW_COPY_AND_ASSIGN(Expression); @@ -1294,6 +1281,11 @@ class StaticInvocation : public Expression { public: static StaticInvocation* ReadFrom(Reader* reader, bool is_const); virtual void WriteTo(Writer* writer); + + explicit StaticInvocation(Procedure* procedure, + Arguments* args, + bool is_const) + : procedure_(procedure), arguments_(args), is_const_(is_const) {} ~StaticInvocation(); virtual void AcceptExpressionVisitor(ExpressionVisitor* visitor); @@ -2793,8 +2785,6 @@ class Program : public TreeNode { virtual void VisitChildren(Visitor* visitor); StringTable& string_table() { return string_table_; } - StringTable& source_uri_table() { return source_uri_table_; } - LineStartingTable& line_starting_table() { return line_starting_table_; } List& libraries() { return libraries_; } Procedure* main_method() { return main_method_; } @@ -2804,8 +2794,6 @@ class Program : public TreeNode { List libraries_; Ref main_method_; StringTable string_table_; - StringTable source_uri_table_; - LineStartingTable line_starting_table_; DISALLOW_COPY_AND_ASSIGN(Program); }; diff --git a/runtime/vm/kernel_binary.cc b/runtime/vm/kernel_binary.cc index a870dd920cca..350690d6b474 100644 --- a/runtime/vm/kernel_binary.cc +++ b/runtime/vm/kernel_binary.cc @@ -355,13 +355,6 @@ class Reader { } } - TokenPosition ReadPosition() { - intptr_t value = ReadUInt(); - // Position is saved as unsigned, - // but actually ranges from -1 and up (thus the -1) - return TokenPosition(value - 1); - } - intptr_t ReadListLength() { return ReadUInt(); } uint8_t ReadByte() { return buffer_[offset_++]; } @@ -557,11 +550,6 @@ class Writer { offset_ += length; } - void WritePosition(TokenPosition position) { - intptr_t value = position.value() + 1; - WriteUInt(value); - } - template void WriteOptional(T* object) { if (object == NULL) { @@ -806,8 +794,8 @@ void StringTable::WriteTo(Writer* writer) { } -void LineStartingTable::ReadFrom(Reader* reader) { - size_ = reader->helper()->program()->source_uri_table().strings().length(); +void LineStartingTable::ReadFrom(Reader* reader, intptr_t length) { + size_ = length; values_ = new intptr_t*[size_]; for (intptr_t i = 0; i < size_; ++i) { intptr_t line_count = reader->ReadUInt(); @@ -815,9 +803,9 @@ void LineStartingTable::ReadFrom(Reader* reader) { line_starts[0] = line_count; intptr_t previous_line_start = 0; for (intptr_t j = 0; j < line_count; ++j) { - intptr_t line_start = reader->ReadUInt() + previous_line_start; - line_starts[j + 1] = line_start; - previous_line_start = line_start; + intptr_t lineStart = reader->ReadUInt() + previous_line_start; + line_starts[j + 1] = lineStart; + previous_line_start = lineStart; } values_[i] = line_starts; } @@ -846,7 +834,7 @@ Library* Library::ReadFrom(Reader* reader) { ASSERT(flags == 0); // external libraries not supported name_ = Reference::ReadStringFrom(reader); import_uri_ = Reference::ReadStringFrom(reader); - source_uri_index_ = reader->ReadUInt(); + reader->ReadUInt(); int num_classes = reader->ReadUInt(); classes().EnsureInitialized(num_classes); @@ -872,7 +860,7 @@ void Library::WriteTo(Writer* writer) { TRACE_WRITE_OFFSET(); name_->WriteTo(writer); import_uri_->WriteTo(writer); - writer->WriteUInt(source_uri_index_); + writer->WriteUInt(0); writer->WriteUInt(classes_.length()); for (int i = 0; i < classes_.length(); i++) { @@ -895,7 +883,7 @@ Class* Class::ReadFrom(Reader* reader) { is_abstract_ = reader->ReadBool(); name_ = Reference::ReadStringFrom(reader); - source_uri_index_ = reader->ReadUInt(); + reader->ReadUInt(); annotations_.ReadFromStatic(reader); return this; @@ -906,7 +894,7 @@ void Class::WriteTo(Writer* writer) { TRACE_WRITE_OFFSET(); writer->WriteBool(is_abstract_); name_->WriteTo(writer); - writer->WriteUInt(source_uri_index_); + writer->WriteUInt(0); annotations_.WriteTo(writer); } @@ -1140,10 +1128,10 @@ Field* Field::ReadFrom(Reader* reader) { Tag tag = reader->ReadTag(); ASSERT(tag == kField); - position_ = reader->ReadPosition(); + reader->ReadUInt(); flags_ = reader->ReadFlags(); name_ = Name::ReadFrom(reader); - source_uri_index_ = reader->ReadUInt(); + reader->ReadUInt(); annotations_.ReadFromStatic(reader); type_ = DartType::ReadFrom(reader); inferred_value_ = reader->ReadOptional(); @@ -1155,10 +1143,10 @@ Field* Field::ReadFrom(Reader* reader) { void Field::WriteTo(Writer* writer) { TRACE_WRITE_OFFSET(); writer->WriteTag(kField); - writer->WritePosition(position_); + writer->WriteUInt(0); writer->WriteFlags(flags_); name_->WriteTo(writer); - writer->WriteUInt(source_uri_index_); + writer->WriteUInt(0); annotations_.WriteTo(writer); type_->WriteTo(writer); writer->WriteOptional(inferred_value_); @@ -1203,7 +1191,7 @@ Procedure* Procedure::ReadFrom(Reader* reader) { kind_ = static_cast(reader->ReadByte()); flags_ = reader->ReadFlags(); name_ = Name::ReadFrom(reader); - source_uri_index_ = reader->ReadUInt(); + reader->ReadUInt(); annotations_.ReadFromStatic(reader); function_ = reader->ReadOptional(); return this; @@ -1218,7 +1206,7 @@ void Procedure::WriteTo(Writer* writer) { writer->WriteByte(kind_); writer->WriteFlags(flags_); name_->WriteTo(writer); - writer->WriteUInt(source_uri_index_); + writer->WriteUInt(0); annotations_.WriteTo(writer); writer->WriteOptional(function_); } @@ -1501,7 +1489,7 @@ void VariableSet::WriteTo(Writer* writer) { PropertyGet* PropertyGet::ReadFrom(Reader* reader) { TRACE_READ_OFFSET(); PropertyGet* get = new PropertyGet(); - get->position_ = reader->ReadPosition(); + reader->ReadUInt(); get->receiver_ = Expression::ReadFrom(reader); get->name_ = Name::ReadFrom(reader); get->interfaceTarget_ = Reference::ReadMemberFrom(reader, true); @@ -1512,7 +1500,7 @@ PropertyGet* PropertyGet::ReadFrom(Reader* reader) { void PropertyGet::WriteTo(Writer* writer) { TRACE_WRITE_OFFSET(); writer->WriteTag(kPropertyGet); - writer->WritePosition(position_); + writer->WriteUInt(0); receiver_->WriteTo(writer); name_->WriteTo(writer); Reference::WriteMemberTo(writer, interfaceTarget_, true); @@ -1522,7 +1510,7 @@ void PropertyGet::WriteTo(Writer* writer) { PropertySet* PropertySet::ReadFrom(Reader* reader) { TRACE_READ_OFFSET(); PropertySet* set = new PropertySet(); - set->position_ = reader->ReadPosition(); + reader->ReadUInt(); set->receiver_ = Expression::ReadFrom(reader); set->name_ = Name::ReadFrom(reader); set->value_ = Expression::ReadFrom(reader); @@ -1534,7 +1522,7 @@ PropertySet* PropertySet::ReadFrom(Reader* reader) { void PropertySet::WriteTo(Writer* writer) { TRACE_WRITE_OFFSET(); writer->WriteTag(kPropertySet); - writer->WritePosition(position_); + writer->WriteUInt(0); receiver_->WriteTo(writer); name_->WriteTo(writer); value_->WriteTo(writer); @@ -1581,7 +1569,7 @@ void DirectPropertySet::WriteTo(Writer* writer) { StaticGet* StaticGet::ReadFrom(Reader* reader) { TRACE_READ_OFFSET(); StaticGet* get = new StaticGet(); - get->position_ = reader->ReadPosition(); + reader->ReadUInt(); get->target_ = Reference::ReadMemberFrom(reader); return get; } @@ -1590,7 +1578,7 @@ StaticGet* StaticGet::ReadFrom(Reader* reader) { void StaticGet::WriteTo(Writer* writer) { TRACE_WRITE_OFFSET(); writer->WriteTag(kStaticGet); - writer->WritePosition(position_); + writer->WriteUInt(0); Reference::WriteMemberTo(writer, target_); } @@ -1648,7 +1636,7 @@ void NamedExpression::WriteTo(Writer* writer) { MethodInvocation* MethodInvocation::ReadFrom(Reader* reader) { TRACE_READ_OFFSET(); MethodInvocation* invocation = new MethodInvocation(); - invocation->position_ = reader->ReadPosition(); + reader->ReadUInt(); invocation->receiver_ = Expression::ReadFrom(reader); invocation->name_ = Name::ReadFrom(reader); invocation->arguments_ = Arguments::ReadFrom(reader); @@ -1660,7 +1648,7 @@ MethodInvocation* MethodInvocation::ReadFrom(Reader* reader) { void MethodInvocation::WriteTo(Writer* writer) { TRACE_WRITE_OFFSET(); writer->WriteTag(kMethodInvocation); - writer->WritePosition(position_); + writer->WriteUInt(0); receiver_->WriteTo(writer); name_->WriteTo(writer); arguments_->WriteTo(writer); @@ -1689,19 +1677,19 @@ void DirectMethodInvocation::WriteTo(Writer* writer) { StaticInvocation* StaticInvocation::ReadFrom(Reader* reader, bool is_const) { TRACE_READ_OFFSET(); - StaticInvocation* invocation = new StaticInvocation(); - invocation->is_const_ = is_const; - invocation->position_ = reader->ReadPosition(); - invocation->procedure_ = Procedure::Cast(Reference::ReadMemberFrom(reader)); - invocation->arguments_ = Arguments::ReadFrom(reader); - return invocation; + + reader->ReadUInt(); + Member* member = Reference::ReadMemberFrom(reader); + Arguments* args = Arguments::ReadFrom(reader); + + return new StaticInvocation(Procedure::Cast(member), args, is_const); } void StaticInvocation::WriteTo(Writer* writer) { TRACE_WRITE_OFFSET(); writer->WriteTag(is_const_ ? kConstStaticInvocation : kStaticInvocation); - writer->WritePosition(position_); + writer->WriteUInt(0); Reference::WriteMemberTo(writer, procedure_); arguments_->WriteTo(writer); } @@ -1712,7 +1700,7 @@ ConstructorInvocation* ConstructorInvocation::ReadFrom(Reader* reader, TRACE_READ_OFFSET(); ConstructorInvocation* invocation = new ConstructorInvocation(); invocation->is_const_ = is_const; - invocation->position_ = reader->ReadPosition(); + reader->ReadUInt(); invocation->target_ = Constructor::Cast(Reference::ReadMemberFrom(reader)); invocation->arguments_ = Arguments::ReadFrom(reader); return invocation; @@ -1723,7 +1711,7 @@ void ConstructorInvocation::WriteTo(Writer* writer) { TRACE_WRITE_OFFSET(); writer->WriteTag(is_const_ ? kConstConstructorInvocation : kConstructorInvocation); - writer->WritePosition(position_); + writer->WriteUInt(0); Reference::WriteMemberTo(writer, target_); arguments_->WriteTo(writer); } @@ -1986,7 +1974,7 @@ void Rethrow::WriteTo(Writer* writer) { Throw* Throw::ReadFrom(Reader* reader) { TRACE_READ_OFFSET(); Throw* t = new Throw(); - t->position_ = reader->ReadPosition(); + reader->ReadUInt(); t->expression_ = Expression::ReadFrom(reader); return t; } @@ -1995,7 +1983,7 @@ Throw* Throw::ReadFrom(Reader* reader) { void Throw::WriteTo(Writer* writer) { TRACE_WRITE_OFFSET(); writer->WriteTag(kThrow); - writer->WritePosition(position_); + writer->WriteUInt(0); expression_->WriteTo(writer); } @@ -2805,8 +2793,10 @@ Program* Program::ReadFrom(Reader* reader) { reader->helper()->set_program(program); program->string_table_.ReadFrom(reader); - program->source_uri_table_.ReadFrom(reader); - program->line_starting_table_.ReadFrom(reader); + StringTable dummy1; + dummy1.ReadFrom(reader); + LineStartingTable dummy2; + dummy2.ReadFrom(reader, dummy1.strings_.length()); int libraries = reader->ReadUInt(); program->libraries().EnsureInitialized(libraries); @@ -2830,8 +2820,10 @@ void Program::WriteTo(Writer* writer) { // NOTE: Currently we don't GC strings and we require that all referenced // strings in nodes are present in [string_table_]. string_table_.WriteTo(writer); - source_uri_table_.WriteTo(writer); - line_starting_table_.WriteTo(writer); + StringTable dummy1; + dummy1.WriteTo(writer); + LineStartingTable dummy2; + dummy2.WriteTo(writer); libraries_.WriteTo(writer); Reference::WriteMemberTo(writer, main_method_); diff --git a/runtime/vm/kernel_reader.cc b/runtime/vm/kernel_reader.cc index 356d19c33694..7e8f6f44fb5d 100644 --- a/runtime/vm/kernel_reader.cc +++ b/runtime/vm/kernel_reader.cc @@ -93,18 +93,10 @@ RawClass* BuildingTranslationHelper::LookupClassByKernelClass(Class* klass) { return reader_->LookupClass(klass).raw(); } -Program* KernelReader::ReadPrecompiledProgram() { - Program* program = ReadPrecompiledKernelFromBuffer(buffer_, buffer_length_); - if (program == NULL) return NULL; - intptr_t source_file_count = program->line_starting_table().size(); - scripts_ = Array::New(source_file_count); - program_ = program; - return program; -} Object& KernelReader::ReadProgram() { ASSERT(!bootstrapping_); - Program* program = ReadPrecompiledProgram(); + Program* program = ReadPrecompiledKernelFromBuffer(buffer_, buffer_length_); if (program == NULL) { const dart::String& error = H.DartString("Failed to read .kernell file"); return Object::Handle(Z, ApiError::New(error)); @@ -168,7 +160,11 @@ void KernelReader::ReadLibrary(Library* kernel_library) { } // Setup toplevel class (which contains library fields/procedures). - Script& script = ScriptAt(kernel_library->source_uri_index()); + Script& script = + Script::Handle(Z, Script::New(Symbols::KernelScriptUri(), + Symbols::Empty(), RawScript::kScriptTag)); + script.SetLocationOffset(0, 0); + script.Tokenize(H.DartString("nop() {}")); dart::Class& toplevel_class = dart::Class::Handle( Z, dart::Class::New(library, Symbols::TopLevel(), script, TokenPosition::kNoSource)); @@ -186,12 +182,10 @@ void KernelReader::ReadLibrary(Library* kernel_library) { ActiveMemberScope active_member_scope(&active_class_, kernel_field); const dart::String& name = H.DartFieldName(kernel_field->name()); - const Object& script_class = - ClassForScriptAt(toplevel_class, kernel_field->source_uri_index()); dart::Field& field = dart::Field::Handle( Z, dart::Field::NewTopLevel(name, kernel_field->IsFinal(), - kernel_field->IsConst(), script_class, - kernel_field->position())); + kernel_field->IsConst(), toplevel_class, + TokenPosition::kNoSource)); field.set_kernel_field(kernel_field); const AbstractType& type = T.TranslateType(kernel_field->type()); field.SetFieldType(type); @@ -298,6 +292,8 @@ dart::Class& KernelReader::ReadClass(const dart::Library& library, ActiveClassScope active_class_scope(&active_class_, kernel_klass, &klass); + TokenPosition pos(0); + for (intptr_t i = 0; i < kernel_klass->fields().length(); i++) { Field* kernel_field = kernel_klass->fields()[i]; ActiveMemberScope active_member_scope(&active_class_, kernel_field); @@ -313,7 +309,7 @@ dart::Class& KernelReader::ReadClass(const dart::Library& library, kernel_field->IsFinal() || kernel_field->IsConst(), kernel_field->IsConst(), false, // is_reflectable - klass, type, kernel_field->position())); + klass, type, pos)); field.set_kernel_field(kernel_field); field.set_has_initializer(kernel_field->initializer() != NULL); GenerateFieldAccessors(klass, field, kernel_field); @@ -334,7 +330,7 @@ dart::Class& KernelReader::ReadClass(const dart::Library& library, false, // is_abstract kernel_constructor->IsExternal(), false, // is_native - klass, TokenPosition::kNoSource)); + klass, pos)); klass.AddFunction(function); function.set_kernel_function(kernel_constructor); function.set_result_type(T.ReceiverType(klass)); @@ -370,6 +366,7 @@ void KernelReader::ReadProcedure(const dart::Library& library, kernel_procedure->function()); const dart::String& name = H.DartProcedureName(kernel_procedure); + TokenPosition pos(0); bool is_method = kernel_klass != NULL && !kernel_procedure->IsStatic(); bool is_abstract = kernel_procedure->IsAbstract(); bool is_external = kernel_procedure->IsExternal(); @@ -405,15 +402,13 @@ void KernelReader::ReadProcedure(const dart::Library& library, break; } } - const Object& script_class = - ClassForScriptAt(owner, kernel_procedure->source_uri_index()); dart::Function& function = dart::Function::ZoneHandle( Z, Function::New(name, GetFunctionType(kernel_procedure), !is_method, // is_static false, // is_const is_abstract, is_external, native_name != NULL, // is_native - script_class, TokenPosition::kNoSource)); + owner, pos)); owner.AddFunction(function); function.set_kernel_function(kernel_procedure); function.set_is_debuggable(false); @@ -433,42 +428,11 @@ void KernelReader::ReadProcedure(const dart::Library& library, } } -const Object& KernelReader::ClassForScriptAt(const dart::Class& klass, - intptr_t source_uri_index) { - Script& correct_script = ScriptAt(source_uri_index); - if (klass.script() != correct_script.raw()) { - // TODO(jensj): We could probably cache this so we don't create - // new PatchClasses all the time - return PatchClass::ZoneHandle(Z, PatchClass::New(klass, correct_script)); - } - return klass; -} - -Script& KernelReader::ScriptAt(intptr_t source_uri_index) { - Script& script = Script::ZoneHandle(Z); - script ^= scripts_.At(source_uri_index); - if (script.IsNull()) { - String* uri = program_->source_uri_table().strings()[source_uri_index]; - script = Script::New(H.DartString(uri), dart::String::ZoneHandle(Z), - RawScript::kKernelTag); - scripts_.SetAt(source_uri_index, script); - intptr_t* line_starts = - program_->line_starting_table().valuesFor(source_uri_index); - intptr_t line_count = line_starts[0]; - Array& array_object = Array::Handle(Z, Array::New(line_count)); - Smi& value = Smi::Handle(Z); - for (intptr_t i = 0; i < line_count; ++i) { - value = Smi::New(line_starts[i + 1]); - array_object.SetAt(i, value); - } - script.set_line_starts(array_object); - } - return script; -} - void KernelReader::GenerateFieldAccessors(const dart::Class& klass, const dart::Field& field, Field* kernel_field) { + TokenPosition pos(0); + if (kernel_field->IsStatic() && kernel_field->initializer() != NULL) { // Static fields with initializers either have the static value set to the // initializer value if it is simple enough or else set to an uninitialized @@ -484,8 +448,6 @@ void KernelReader::GenerateFieldAccessors(const dart::Class& klass, } const dart::String& getter_name = H.DartGetterName(kernel_field->name()); - const Object& script_class = - ClassForScriptAt(klass, kernel_field->source_uri_index()); Function& getter = Function::ZoneHandle( Z, Function::New( @@ -502,7 +464,7 @@ void KernelReader::GenerateFieldAccessors(const dart::Class& klass, false, // is_abstract false, // is_external false, // is_native - script_class, kernel_field->position())); + klass, pos)); klass.AddFunction(getter); if (klass.IsTopLevel()) { dart::Library& library = dart::Library::Handle(Z, klass.library()); @@ -524,7 +486,7 @@ void KernelReader::GenerateFieldAccessors(const dart::Class& klass, false, // is_abstract false, // is_external false, // is_native - script_class, kernel_field->position())); + klass, pos)); klass.AddFunction(setter); setter.set_kernel_function(kernel_field); setter.set_result_type(Object::void_type()); @@ -657,15 +619,26 @@ dart::Class& KernelReader::LookupClass(Class* klass) { // The class needs to have a script because all the functions in the class // will inherit it. The predicate Function::IsOptimizable uses the // absence of a script to detect test functions that should not be - // optimized. - Script& script = ScriptAt(klass->source_uri_index()); - handle = &dart::Class::Handle( - Z, dart::Class::New(library, name, script, TokenPosition::kNoSource)); + // optimized. Use a dummy script. + // + // TODO(27590): We shouldn't need a dummy script per class. At the + // least we could have a singleton. At best, we'd change IsOptimizable to + // detect test functions some other way (like simply not setting the + // optimizable bit on those functions in the first place). + TokenPosition pos(0); + Script& script = Script::Handle( + Z, Script::New(Symbols::KernelScriptUri(), Symbols::Empty(), + RawScript::kScriptTag)); + handle = + &dart::Class::Handle(Z, dart::Class::New(library, name, script, pos)); library.AddClass(*handle); } else if (handle->script() == Script::null()) { // When bootstrapping we can encounter classes that do not yet have a // dummy script. - Script& script = ScriptAt(klass->source_uri_index()); + TokenPosition pos(0); + Script& script = Script::Handle( + Z, Script::New(Symbols::KernelScriptUri(), Symbols::Empty(), + RawScript::kScriptTag)); handle->set_script(script); } // Insert the class in the cache before calling ReadPreliminaryClass so diff --git a/runtime/vm/kernel_reader.h b/runtime/vm/kernel_reader.h index a361c141a5cb..6b1db8a0033f 100644 --- a/runtime/vm/kernel_reader.h +++ b/runtime/vm/kernel_reader.h @@ -58,8 +58,6 @@ class KernelReader { : thread_(dart::Thread::Current()), zone_(thread_->zone()), isolate_(thread_->isolate()), - scripts_(Array::ZoneHandle(zone_)), - program_(NULL), translation_helper_(this, thread_, zone_, isolate_), type_translator_(&translation_helper_, &active_class_, @@ -68,9 +66,6 @@ class KernelReader { buffer_(buffer), buffer_length_(len) {} - // Returns either pointer to a program or null. - Program* ReadPrecompiledProgram(); - // Returns either a library or a failure object. dart::Object& ReadProgram(); @@ -94,13 +89,6 @@ class KernelReader { Procedure* procedure, Class* kernel_klass = NULL); - // If klass's script is not the script at the uri index, return a PatchClass - // for klass whose script corresponds to the uri index. - // Otherwise return klass. - const Object& ClassForScriptAt(const dart::Class& klass, - intptr_t source_uri_index); - Script& ScriptAt(intptr_t source_uri_index); - void GenerateFieldAccessors(const dart::Class& klass, const dart::Field& field, Field* kernel_field); @@ -116,8 +104,6 @@ class KernelReader { dart::Thread* thread_; dart::Zone* zone_; dart::Isolate* isolate_; - Array& scripts_; - Program* program_; ActiveClass active_class_; BuildingTranslationHelper translation_helper_; DartTypeTranslator type_translator_; diff --git a/runtime/vm/kernel_to_il.cc b/runtime/vm/kernel_to_il.cc index 9ebcfc1a87cd..c344d6d0b860 100644 --- a/runtime/vm/kernel_to_il.cc +++ b/runtime/vm/kernel_to_il.cc @@ -2287,26 +2287,24 @@ Fragment FlowGraphBuilder::IntConstant(int64_t value) { } -Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, - const dart::String& name, +Fragment FlowGraphBuilder::InstanceCall(const dart::String& name, Token::Kind kind, intptr_t argument_count, intptr_t num_args_checked) { - return InstanceCall(position, name, kind, argument_count, Array::null_array(), + return InstanceCall(name, kind, argument_count, Array::null_array(), num_args_checked); } -Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, - const dart::String& name, +Fragment FlowGraphBuilder::InstanceCall(const dart::String& name, Token::Kind kind, intptr_t argument_count, const Array& argument_names, intptr_t num_args_checked) { ArgumentArray arguments = GetArguments(argument_count); - InstanceCallInstr* call = - new (Z) InstanceCallInstr(position, name, kind, arguments, argument_names, - num_args_checked, ic_data_array_); + InstanceCallInstr* call = new (Z) + InstanceCallInstr(TokenPosition::kNoSource, name, kind, arguments, + argument_names, num_args_checked, ic_data_array_); Push(call); return Fragment(call); } @@ -2323,10 +2321,11 @@ Fragment FlowGraphBuilder::ClosureCall(int argument_count, } -Fragment FlowGraphBuilder::ThrowException(TokenPosition position) { +Fragment FlowGraphBuilder::ThrowException() { Fragment instructions; instructions += Drop(); - instructions += Fragment(new (Z) ThrowInstr(position)).closed(); + instructions += + Fragment(new (Z) ThrowInstr(TokenPosition::kNoSource)).closed(); // Use it's side effect of leaving a constant on the stack (does not change // the graph). NullConstant(); @@ -2472,10 +2471,9 @@ Fragment FlowGraphBuilder::Return() { } -Fragment FlowGraphBuilder::StaticCall(TokenPosition position, - const Function& target, +Fragment FlowGraphBuilder::StaticCall(const Function& target, intptr_t argument_count) { - return StaticCall(position, target, argument_count, Array::null_array()); + return StaticCall(target, argument_count, Array::null_array()); } @@ -2501,13 +2499,13 @@ static intptr_t GetResultCidOfListFactory(Zone* zone, } -Fragment FlowGraphBuilder::StaticCall(TokenPosition position, - const Function& target, +Fragment FlowGraphBuilder::StaticCall(const Function& target, intptr_t argument_count, const Array& argument_names) { ArgumentArray arguments = GetArguments(argument_count); - StaticCallInstr* call = new (Z) StaticCallInstr( - position, target, argument_names, arguments, ic_data_array_); + StaticCallInstr* call = + new (Z) StaticCallInstr(TokenPosition::kNoSource, target, argument_names, + arguments, ic_data_array_); const intptr_t list_cid = GetResultCidOfListFactory(Z, target, argument_count); if (list_cid != kDynamicCid) { @@ -2647,12 +2645,12 @@ Fragment FlowGraphBuilder::ThrowTypeError() { instructions += Constant(H.DartSymbol("Malformed type.")); instructions += PushArgument(); // message - instructions += StaticCall(TokenPosition::kNoSource, constructor, 5); + instructions += StaticCall(constructor, 5); instructions += Drop(); // Throw the exception instructions += PushArgument(); - instructions += ThrowException(TokenPosition::kNoSource); + instructions += ThrowException(); return instructions; } @@ -2687,7 +2685,7 @@ Fragment FlowGraphBuilder::ThrowNoSuchMethodError() { instructions += NullConstant(); instructions += PushArgument(); // existingArgumentNames - instructions += StaticCall(TokenPosition::kNoSource, throw_function, 6); + instructions += StaticCall(throw_function, 6); // Leave "result" on the stack since callers expect it to be there (even // though the function will result in an exception). @@ -3449,8 +3447,7 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfImplicitClosureFunction( // Forward them to the target. intptr_t argument_count = positional_argument_count + named_argument_count; if (!target.is_static()) ++argument_count; - body += StaticCall(TokenPosition::kNoSource, target, argument_count, - argument_names); + body += StaticCall(target, argument_count, argument_names); // Return the result. body += Return(); @@ -3537,7 +3534,7 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfNoSuchMethodDispatcher( Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName( Symbols::AllocateInvocationMirror()))); ASSERT(!allocation_function.IsNull()); - body += StaticCall(TokenPosition::kMinSource, allocation_function, 4); + body += StaticCall(allocation_function, 4); body += PushArgument(); // For the call to noSuchMethod. ArgumentsDescriptor two_arguments( @@ -3553,7 +3550,7 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfNoSuchMethodDispatcher( dart::Class::Handle(Z, I->object_store()->object_class()), Symbols::NoSuchMethod(), two_arguments); } - body += StaticCall(TokenPosition::kMinSource, no_such_method, 2); + body += StaticCall(no_such_method, 2); body += Return(); return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); @@ -3617,8 +3614,7 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfInvokeFieldDispatcher( // Invoke the getter to get the field value. body += LoadLocal(scope->VariableAt(0)); body += PushArgument(); - body += - InstanceCall(TokenPosition::kMinSource, getter_name, Token::kGET, 1); + body += InstanceCall(getter_name, Token::kGET, 1); } body += PushArgument(); @@ -3637,8 +3633,8 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfInvokeFieldDispatcher( body += ClosureCall(descriptor.Count(), argument_names); } else { - body += InstanceCall(TokenPosition::kMinSource, Symbols::Call(), - Token::kILLEGAL, descriptor.Count(), argument_names); + body += InstanceCall(Symbols::Call(), Token::kILLEGAL, descriptor.Count(), + argument_names); } body += Return(); @@ -3751,8 +3747,7 @@ Fragment FlowGraphBuilder::TranslateInitializers( const Function& target = Function::ZoneHandle( Z, H.LookupConstructorByKernelConstructor(init->target())); intptr_t argument_count = init->arguments()->count() + 1; - instructions += StaticCall(TokenPosition::kNoSource, target, - argument_count, argument_names); + instructions += StaticCall(target, argument_count, argument_names); instructions += Drop(); } else if (initializer->IsRedirectingInitializer()) { RedirectingInitializer* init = RedirectingInitializer::Cast(initializer); @@ -3767,8 +3762,7 @@ Fragment FlowGraphBuilder::TranslateInitializers( const Function& target = Function::ZoneHandle( Z, H.LookupConstructorByKernelConstructor(init->target())); intptr_t argument_count = init->arguments()->count() + 1; - instructions += StaticCall(TokenPosition::kNoSource, target, - argument_count, argument_names); + instructions += StaticCall(target, argument_count, argument_names); instructions += Drop(); } else if (initializer->IsLocalInitializer()) { // The other initializers following this one might read the variable. This @@ -4195,7 +4189,7 @@ void FlowGraphBuilder::VisitStaticGet(StaticGet* node) { Fragment instructions = Constant(field); fragment_ = instructions + LoadStaticField(); } else { - fragment_ = StaticCall(node->position(), getter, 0); + fragment_ = StaticCall(getter, 0); } } } else { @@ -4204,7 +4198,7 @@ void FlowGraphBuilder::VisitStaticGet(StaticGet* node) { Z, H.LookupStaticMethodByKernelProcedure(procedure)); if (procedure->kind() == Procedure::kGetter) { - fragment_ = StaticCall(node->position(), target, 0); + fragment_ = StaticCall(target, 0); } else if (procedure->kind() == Procedure::kMethod) { ASSERT(procedure->IsStatic()); Function& closure_function = @@ -4245,7 +4239,7 @@ void FlowGraphBuilder::VisitStaticSet(StaticSet* node) { Procedure* procedure = Procedure::Cast(target); const Function& target = Function::ZoneHandle( Z, H.LookupStaticMethodByKernelProcedure(procedure)); - instructions += StaticCall(node->position(), target, 1); + instructions += StaticCall(target, 1); // Drop the unused result & leave the stored value on the stack. fragment_ = instructions + Drop(); @@ -4257,8 +4251,7 @@ void FlowGraphBuilder::VisitPropertyGet(PropertyGet* node) { Fragment instructions = TranslateExpression(node->receiver()); instructions += PushArgument(); const dart::String& getter_name = H.DartGetterName(node->name()); - fragment_ = instructions + - InstanceCall(node->position(), getter_name, Token::kGET, 1); + fragment_ = instructions + InstanceCall(getter_name, Token::kGET, 1); } @@ -4272,7 +4265,7 @@ void FlowGraphBuilder::VisitPropertySet(PropertySet* node) { instructions += PushArgument(); const dart::String& setter_name = H.DartSetterName(node->name()); - instructions += InstanceCall(node->position(), setter_name, Token::kSET, 2); + instructions += InstanceCall(setter_name, Token::kSET, 2); fragment_ = instructions + Drop(); } @@ -4302,7 +4295,7 @@ void FlowGraphBuilder::VisitDirectPropertyGet(DirectPropertyGet* node) { Fragment instructions = TranslateExpression(node->receiver()); instructions += PushArgument(); - fragment_ = instructions + StaticCall(node->position(), target, 1); + fragment_ = instructions + StaticCall(target, 1); } @@ -4319,7 +4312,7 @@ void FlowGraphBuilder::VisitDirectPropertySet(DirectPropertySet* node) { instructions += TranslateExpression(node->value()); instructions += StoreLocal(value); instructions += PushArgument(); - instructions += StaticCall(node->position(), target, 2); + instructions += StaticCall(target, 2); fragment_ = instructions + Drop(); } @@ -4404,8 +4397,7 @@ void FlowGraphBuilder::VisitStaticInvocation(StaticInvocation* node) { instructions += StrictCompare(Token::kEQ_STRICT, /*number_check=*/true); } else { instructions += TranslateArguments(node->arguments(), NULL); - instructions += - StaticCall(node->position(), target, argument_count, argument_names); + instructions += StaticCall(target, argument_count, argument_names); if (target.IsGenerativeConstructor()) { // Drop the result of the constructor call and leave [instance_variable] @@ -4462,9 +4454,8 @@ void FlowGraphBuilder::VisitMethodInvocation(MethodInvocation* node) { num_args_checked = argument_count; } - fragment_ = instructions + InstanceCall(node->position(), name, token_kind, - argument_count, argument_names, - num_args_checked); + fragment_ = instructions + InstanceCall(name, token_kind, argument_count, + argument_names, num_args_checked); } @@ -4481,8 +4472,7 @@ void FlowGraphBuilder::VisitDirectMethodInvocation( Fragment instructions = TranslateExpression(node->receiver()); instructions += PushArgument(); instructions += TranslateArguments(node->arguments(), &argument_names); - fragment_ = instructions + StaticCall(node->position(), target, - argument_count, argument_names); + fragment_ = instructions + StaticCall(target, argument_count, argument_names); } @@ -4542,8 +4532,7 @@ void FlowGraphBuilder::VisitConstructorInvocation(ConstructorInvocation* node) { const Function& target = Function::ZoneHandle( Z, H.LookupConstructorByKernelConstructor(klass, node->target())); intptr_t argument_count = node->arguments()->count() + 1; - instructions += - StaticCall(node->position(), target, argument_count, argument_names); + instructions += StaticCall(target, argument_count, argument_names); fragment_ = instructions + Drop(); } @@ -4586,8 +4575,7 @@ void FlowGraphBuilder::VisitIsExpression(IsExpression* node) { instructions += PushArgument(); // Negate?. instructions += - InstanceCall(TokenPosition::kNoSource, - dart::Library::PrivateCoreLibName(Symbols::_instanceOf()), + InstanceCall(dart::Library::PrivateCoreLibName(Symbols::_instanceOf()), Token::kIS, 4); } @@ -4627,7 +4615,6 @@ void FlowGraphBuilder::VisitAsExpression(AsExpression* node) { instructions += PushArgument(); // Type. instructions += InstanceCall( - TokenPosition::kNoSource, dart::Library::PrivateCoreLibName(Symbols::_as()), Token::kAS, 3); } @@ -4774,7 +4761,7 @@ void FlowGraphBuilder::VisitListLiteral(ListLiteral* node) { const Function& factory_method = Function::ZoneHandle( Z, factory_class.LookupFactory( dart::Library::PrivateCoreLibName(Symbols::ListLiteralFactory()))); - fragment_ = instructions + StaticCall(node->position(), factory_method, 2); + fragment_ = instructions + StaticCall(factory_method, 2); } @@ -4825,7 +4812,7 @@ void FlowGraphBuilder::VisitMapLiteral(MapLiteral* node) { } instructions += PushArgument(); // The array. - fragment_ = instructions + StaticCall(node->position(), factory_method, 2); + fragment_ = instructions + StaticCall(factory_method, 2); } @@ -4846,7 +4833,7 @@ void FlowGraphBuilder::VisitThrow(Throw* node) { instructions += TranslateExpression(node->expression()); instructions += PushArgument(); - instructions += ThrowException(node->position()); + instructions += ThrowException(); ASSERT(instructions.is_closed()); fragment_ = instructions; @@ -5130,8 +5117,7 @@ void FlowGraphBuilder::VisitForInStatement(ForInStatement* node) { const dart::String& iterator_getter = dart::String::ZoneHandle( Z, dart::Field::GetterSymbol(Symbols::Iterator())); - instructions += - InstanceCall(TokenPosition::kNoSource, iterator_getter, Token::kGET, 1); + instructions += InstanceCall(iterator_getter, Token::kGET, 1); LocalVariable* iterator = scopes_->iterator_variables[for_in_depth_]; instructions += StoreLocal(iterator); instructions += Drop(); @@ -5140,8 +5126,7 @@ void FlowGraphBuilder::VisitForInStatement(ForInStatement* node) { ++loop_depth_; Fragment condition = LoadLocal(iterator); condition += PushArgument(); - condition += InstanceCall(TokenPosition::kNoSource, Symbols::MoveNext(), - Token::kILLEGAL, 1); + condition += InstanceCall(Symbols::MoveNext(), Token::kILLEGAL, 1); TargetEntryInstr* body_entry; TargetEntryInstr* loop_exit; condition += BranchIfTrue(&body_entry, &loop_exit); @@ -5152,8 +5137,7 @@ void FlowGraphBuilder::VisitForInStatement(ForInStatement* node) { body += PushArgument(); const dart::String& current_getter = dart::String::ZoneHandle( Z, dart::Field::GetterSymbol(Symbols::Current())); - body += - InstanceCall(TokenPosition::kNoSource, current_getter, Token::kGET, 1); + body += InstanceCall(current_getter, Token::kGET, 1); body += StoreLocal(LookupVariable(node->variable())); body += Drop(); body += TranslateStatement(node->body()); @@ -5274,12 +5258,12 @@ void FlowGraphBuilder::VisitSwitchStatement(SwitchStatement* node) { body_fragment += NullConstant(); body_fragment += PushArgument(); // line - body_fragment += StaticCall(TokenPosition::kNoSource, constructor, 3); + body_fragment += StaticCall(constructor, 3); body_fragment += Drop(); // Throw the exception body_fragment += PushArgument(); - body_fragment += ThrowException(TokenPosition::kNoSource); + body_fragment += ThrowException(); body_fragment += Drop(); } @@ -5343,10 +5327,10 @@ void FlowGraphBuilder::VisitSwitchStatement(SwitchStatement* node) { current_instructions += PushArgument(); current_instructions += LoadLocal(scopes_->switch_variable); current_instructions += PushArgument(); - current_instructions += InstanceCall( - TokenPosition::kNoSource, Symbols::EqualOperator(), Token::kEQ, - /*argument_count=*/2, - /*num_args_checked=*/2); + current_instructions += + InstanceCall(Symbols::EqualOperator(), Token::kEQ, + /*argument_count=*/2, + /*num_args_checked=*/2); current_instructions += BranchIfTrue(&then, &otherwise); Fragment then_fragment(then); @@ -5466,12 +5450,12 @@ void FlowGraphBuilder::VisitAssertStatement(AssertStatement* node) { otherwise_fragment += IntConstant(0); otherwise_fragment += PushArgument(); // column - otherwise_fragment += StaticCall(TokenPosition::kNoSource, constructor, 5); + otherwise_fragment += StaticCall(constructor, 5); otherwise_fragment += Drop(); // Throw _AssertionError exception. otherwise_fragment += PushArgument(); - otherwise_fragment += ThrowException(TokenPosition::kNoSource); + otherwise_fragment += ThrowException(); otherwise_fragment += Drop(); fragment_ = Fragment(instructions.entry, then); @@ -5626,7 +5610,6 @@ void FlowGraphBuilder::VisitTryCatch(class TryCatch* node) { catch_body += Constant(Object::bool_false()); catch_body += PushArgument(); // negate catch_body += InstanceCall( - TokenPosition::kNoSource, dart::Library::PrivateCoreLibName(Symbols::_instanceOf()), Token::kIS, 4); @@ -5744,7 +5727,6 @@ Fragment FlowGraphBuilder::TranslateFunctionNode(FunctionNode* node, for (intptr_t i = 0; i < scopes_->function_scopes.length(); ++i) { if (scopes_->function_scopes[i].function != node) continue; - // NOTE: This is not TokenPosition in the general sense! function = I->LookupClosureFunction(parsed_function_->function(), TokenPosition(i)); if (function.IsNull()) { @@ -5756,7 +5738,6 @@ Fragment FlowGraphBuilder::TranslateFunctionNode(FunctionNode* node, name = &H.DartSymbol( FunctionDeclaration::Cast(parent)->variable()->name()); } - // NOTE: This is not TokenPosition in the general sense! function = Function::NewClosureFunction( *name, parsed_function_->function(), TokenPosition(i)); function.set_is_debuggable(false); diff --git a/runtime/vm/kernel_to_il.h b/runtime/vm/kernel_to_il.h index 3f9db3e994e2..5f2539b1b6df 100644 --- a/runtime/vm/kernel_to_il.h +++ b/runtime/vm/kernel_to_il.h @@ -753,19 +753,17 @@ class FlowGraphBuilder : public TreeVisitor { Fragment CreateArray(); Fragment Goto(JoinEntryInstr* destination); Fragment IntConstant(int64_t value); - Fragment InstanceCall(TokenPosition position, - const dart::String& name, + Fragment InstanceCall(const dart::String& name, Token::Kind kind, intptr_t argument_count, intptr_t num_args_checked = 1); - Fragment InstanceCall(TokenPosition position, - const dart::String& name, + Fragment InstanceCall(const dart::String& name, Token::Kind kind, intptr_t argument_count, const Array& argument_names, intptr_t num_args_checked = 1); Fragment ClosureCall(int argument_count, const Array& argument_names); - Fragment ThrowException(TokenPosition position); + Fragment ThrowException(); Fragment RethrowException(int catch_try_index); Fragment LoadClassId(); Fragment LoadField(const dart::Field& field); @@ -782,11 +780,8 @@ class FlowGraphBuilder : public TreeVisitor { Fragment NativeCall(const dart::String* name, const Function* function); Fragment PushArgument(); Fragment Return(); - Fragment StaticCall(TokenPosition position, - const Function& target, - intptr_t argument_count); - Fragment StaticCall(TokenPosition position, - const Function& target, + Fragment StaticCall(const Function& target, intptr_t argument_count); + Fragment StaticCall(const Function& target, intptr_t argument_count, const Array& argument_names); Fragment StoreIndexed(intptr_t class_id); diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc index 980e62bfe93b..ccd7f25336eb 100644 --- a/runtime/vm/object.cc +++ b/runtime/vm/object.cc @@ -8782,8 +8782,6 @@ const char* Script::GetKindAsCString() const { return "patch"; case RawScript::kEvaluateTag: return "evaluate"; - case RawScript::kKernelTag: - return "kernel"; default: UNIMPLEMENTED(); } @@ -8806,10 +8804,6 @@ void Script::set_source(const String& value) const { StorePointer(&raw_ptr()->source_, value.raw()); } -void Script::set_line_starts(const Array& value) const { - StorePointer(&raw_ptr()->line_starts_, value.raw()); -} - void Script::set_kind(RawScript::Kind value) const { StoreNonPointer(&raw_ptr()->kind_, value); @@ -8860,51 +8854,10 @@ void Script::GetTokenLocation(TokenPosition token_pos, intptr_t* token_len) const { ASSERT(line != NULL); Zone* zone = Thread::Current()->zone(); - - if (kind() == RawScript::kKernelTag) { - const Array& line_starts_array = Array::Handle(line_starts()); - if (line_starts_array.IsNull()) { - // Scripts in the AOT snapshot do not have a line starts array. - *line = -1; - if (column != NULL) { - *column = -1; - } - if (token_len != NULL) { - *token_len = 1; - } - return; - } - ASSERT(line_starts_array.Length() > 0); - intptr_t offset = token_pos.value(); - int min = 0; - int max = line_starts_array.Length() - 1; - - // Binary search to find the line containing this offset. - Smi& smi = Smi::Handle(); - while (min < max) { - int midpoint = (max - min + 1) / 2 + min; - - smi ^= line_starts_array.At(midpoint); - if (smi.Value() > offset) { - max = midpoint - 1; - } else { - min = midpoint; - } - } - *line = min + 1; - if (column != NULL) { - smi ^= line_starts_array.At(min); - *column = offset - smi.Value() + 1; - } - if (token_len != NULL) { - *token_len = 1; - } - return; - } - const TokenStream& tkns = TokenStream::Handle(zone, tokens()); if (tkns.IsNull()) { - ASSERT((Dart::snapshot_kind() == Snapshot::kAppNoJIT)); + ASSERT((Dart::snapshot_kind() == Snapshot::kAppNoJIT) || + (url() == Symbols::KernelScriptUri().raw())); *line = -1; if (column != NULL) { *column = -1; @@ -8914,7 +8867,7 @@ void Script::GetTokenLocation(TokenPosition token_pos, } return; } - if (!HasSource()) { + if (column == NULL) { TokenStream::Iterator tkit(zone, tkns, TokenPosition::kMinSource, TokenStream::Iterator::kAllTokens); intptr_t cur_line = line_offset() + 1; @@ -8933,9 +8886,7 @@ void Script::GetTokenLocation(TokenPosition token_pos, scanner.ScanTo(src_pos); intptr_t relative_line = scanner.CurrentPosition().line; *line = relative_line + line_offset(); - if (column != NULL) { - *column = scanner.CurrentPosition().column; - } + *column = scanner.CurrentPosition().column; if (token_len != NULL) { if (scanner.current_token().literal != NULL) { *token_len = scanner.current_token().literal->Length(); @@ -8944,7 +8895,7 @@ void Script::GetTokenLocation(TokenPosition token_pos, } } // On the first line of the script we must add the column offset. - if (column != NULL && relative_line == 1) { + if (relative_line == 1) { *column += col_offset(); } } @@ -22361,7 +22312,11 @@ static intptr_t PrintOneStacktrace(Zone* zone, intptr_t line = -1; intptr_t column = -1; if (!script.IsNull() && token_pos.IsReal()) { - script.GetTokenLocation(token_pos, &line, &column); + if (script.HasSource()) { + script.GetTokenLocation(token_pos, &line, &column); + } else { + script.GetTokenLocation(token_pos, &line, NULL); + } } char* chars = NULL; if (column >= 0) { diff --git a/runtime/vm/object.h b/runtime/vm/object.h index bf2b0098a940..6145fde64da0 100644 --- a/runtime/vm/object.h +++ b/runtime/vm/object.h @@ -3503,10 +3503,6 @@ class Script : public Object { RawTokenStream* tokens() const { return raw_ptr()->tokens_; } - RawArray* line_starts() const { return raw_ptr()->line_starts_; } - - void set_line_starts(const Array& value) const; - void Tokenize(const String& private_key, bool use_shared_tokens = true) const; RawLibrary* FindLibrary() const; diff --git a/runtime/vm/raw_object.h b/runtime/vm/raw_object.h index 9097b1d65012..94c98224ebe0 100644 --- a/runtime/vm/raw_object.h +++ b/runtime/vm/raw_object.h @@ -970,7 +970,6 @@ class RawScript : public RawObject { kSourceTag, kPatchTag, kEvaluateTag, - kKernelTag, }; private: @@ -980,7 +979,6 @@ class RawScript : public RawObject { RawString* url_; RawString* resolved_url_; RawArray* compile_time_constants_; - RawArray* line_starts_; RawTokenStream* tokens_; RawString* source_; RawObject** to() { return reinterpret_cast(&ptr()->source_); } diff --git a/runtime/vm/symbols.h b/runtime/vm/symbols.h index f15485bd206b..344015c1b3f8 100644 --- a/runtime/vm/symbols.h +++ b/runtime/vm/symbols.h @@ -406,7 +406,8 @@ class ObjectPointerVisitor; V(_classRangeCheck, "_classRangeCheck") \ V(_classRangeCheckNegative, "_classRangeCheckNegative") \ V(GetRuntimeType, "get:runtimeType") \ - V(HaveSameRuntimeType, "_haveSameRuntimeType") + V(HaveSameRuntimeType, "_haveSameRuntimeType") \ + V(KernelScriptUri, "kernel:script") // Contains a list of frequently used strings in a canonicalized form. This