[vm] Remove dead lazy reading code of line starts / ...

This was originally added for kbc in [0]. But it seems this is unused
in the kernel frontend.

For performance reasons we may want to implement this at some point
properly but until then let's remove the dead code.

[0] https://dart-review.googlesource.com/c/sdk/+/112680

TEST=ci

Change-Id: Ic4f4edd976c625316f77822a4067763ab31ea3ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313122
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
diff --git a/runtime/vm/kernel.cc b/runtime/vm/kernel.cc
index ea87bea..59fe438 100644
--- a/runtime/vm/kernel.cc
+++ b/runtime/vm/kernel.cc
@@ -206,7 +206,6 @@
 static void CollectKernelDataTokenPositions(
     const ExternalTypedData& kernel_data,
     const Script& script,
-    const Script& entry_script,
     intptr_t kernel_offset,
     intptr_t data_kernel_offset,
     Zone* zone,
@@ -218,7 +217,7 @@
 
   KernelTokenPositionCollector token_position_collector(
       zone, helper, script, kernel_data, data_kernel_offset,
-      entry_script.kernel_script_index(), script.kernel_script_index(),
+      script.kernel_script_index(), script.kernel_script_index(),
       token_positions);
 
   token_position_collector.CollectTokenPositions(kernel_offset);
@@ -227,7 +226,6 @@
 void CollectTokenPositionsFor(const Script& interesting_script) {
   Thread* thread = Thread::Current();
   Zone* zone = thread->zone();
-  interesting_script.LookupSourceAndLineStarts(zone);
   TranslationHelper helper(thread);
   helper.InitFromScript(interesting_script);
 
@@ -271,8 +269,7 @@
             }
             data = temp_field.KernelData();
             CollectKernelDataTokenPositions(
-                data, interesting_script, entry_script,
-                temp_field.kernel_offset(),
+                data, interesting_script, temp_field.kernel_offset(),
                 temp_field.KernelDataProgramOffset(), zone, &helper,
                 &token_positions);
           }
@@ -285,8 +282,7 @@
             }
             data = temp_function.KernelData();
             CollectKernelDataTokenPositions(
-                data, interesting_script, entry_script,
-                temp_function.kernel_offset(),
+                data, interesting_script, temp_function.kernel_offset(),
                 temp_function.KernelDataProgramOffset(), zone, &helper,
                 &token_positions);
           }
@@ -303,9 +299,9 @@
           if (entry_script.ptr() != interesting_script.ptr()) {
             continue;
           }
-          CollectKernelDataTokenPositions(
-              data, interesting_script, entry_script, class_offset,
-              library_kernel_offset, zone, &helper, &token_positions);
+          CollectKernelDataTokenPositions(data, interesting_script,
+                                          class_offset, library_kernel_offset,
+                                          zone, &helper, &token_positions);
         }
       } else if (entry.IsFunction()) {
         temp_function ^= entry.ptr();
@@ -314,7 +310,7 @@
           continue;
         }
         data = temp_function.KernelData();
-        CollectKernelDataTokenPositions(data, interesting_script, entry_script,
+        CollectKernelDataTokenPositions(data, interesting_script,
                                         temp_function.kernel_offset(),
                                         temp_function.KernelDataProgramOffset(),
                                         zone, &helper, &token_positions);
@@ -330,7 +326,7 @@
         }
         data = field.KernelData();
         CollectKernelDataTokenPositions(
-            data, interesting_script, entry_script, field.kernel_offset(),
+            data, interesting_script, field.kernel_offset(),
             field.KernelDataProgramOffset(), zone, &helper, &token_positions);
       }
     }
@@ -346,7 +342,6 @@
 ArrayPtr CollectConstConstructorCoverageFrom(const Script& interesting_script) {
   Thread* thread = Thread::Current();
   Zone* zone = thread->zone();
-  interesting_script.LookupSourceAndLineStarts(zone);
   TranslationHelper helper(thread);
   helper.InitFromScript(interesting_script);
 
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 694b201..d2d5e14 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -12866,44 +12866,11 @@
   return program_info.string_offsets();
 }
 
-void Script::LookupSourceAndLineStarts(Zone* zone) const {
-#if !defined(DART_PRECOMPILED_RUNTIME)
-  if (!IsLazyLookupSourceAndLineStarts()) {
-    return;
-  }
-  const String& uri = String::Handle(zone, resolved_url());
-  ASSERT(uri.IsSymbol());
-  if (uri.Length() > 0) {
-    // Entry included only to provide URI - actual source should already exist
-    // in the VM, so try to find it.
-    Library& lib = Library::Handle(zone);
-    Script& script = Script::Handle(zone);
-    const GrowableObjectArray& libs = GrowableObjectArray::Handle(
-        zone, IsolateGroup::Current()->object_store()->libraries());
-    for (intptr_t i = 0; i < libs.Length(); i++) {
-      lib ^= libs.At(i);
-      script = lib.LookupScript(uri, /* useResolvedUri = */ true);
-      if (!script.IsNull()) {
-        const auto& source = String::Handle(zone, script.Source());
-        const auto& starts = TypedData::Handle(zone, script.line_starts());
-        if (!source.IsNull() || !starts.IsNull()) {
-          set_source(source);
-          set_line_starts(starts);
-          break;
-        }
-      }
-    }
-  }
-  SetLazyLookupSourceAndLineStarts(false);
-#endif  // !defined(DART_PRECOMPILED_RUNTIME)
-}
-
 GrowableObjectArrayPtr Script::GenerateLineNumberArray() const {
   Zone* zone = Thread::Current()->zone();
   const GrowableObjectArray& info =
       GrowableObjectArray::Handle(zone, GrowableObjectArray::New());
   const Object& line_separator = Object::Handle(zone);
-  LookupSourceAndLineStarts(zone);
   if (line_starts() == TypedData::null()) {
     // Scripts in the AOT snapshot do not have a line starts array.
     // A well-formed line number array has a leading null.
@@ -12958,7 +12925,6 @@
             untag()->flags_and_max_position_));
   }
   auto const zone = Thread::Current()->zone();
-  LookupSourceAndLineStarts(zone);
   if (!HasCachedMaxPosition() && line_starts() != TypedData::null()) {
     const auto& starts = TypedData::Handle(zone, line_starts());
     kernel::KernelLineStartsReader reader(starts, zone);
@@ -13017,17 +12983,6 @@
 }
 
 #if !defined(DART_PRECOMPILED_RUNTIME)
-void Script::SetLazyLookupSourceAndLineStarts(bool value) const {
-  StoreNonPointer(&untag()->flags_and_max_position_,
-                  UntaggedScript::LazyLookupSourceAndLineStartsBit::update(
-                      value, untag()->flags_and_max_position_));
-}
-
-bool Script::IsLazyLookupSourceAndLineStarts() const {
-  return UntaggedScript::LazyLookupSourceAndLineStartsBit::decode(
-      untag()->flags_and_max_position_);
-}
-
 bool Script::HasCachedMaxPosition() const {
   return UntaggedScript::HasCachedMaxPositionBit::decode(
       untag()->flags_and_max_position_);
@@ -13088,7 +13043,6 @@
   if (!token_pos.IsReal()) return false;
 
   auto const zone = Thread::Current()->zone();
-  LookupSourceAndLineStarts(zone);
   const TypedData& line_starts_data = TypedData::Handle(zone, line_starts());
   if (line_starts_data.IsNull()) return false;
   kernel::KernelLineStartsReader line_starts_reader(line_starts_data, zone);
@@ -13103,7 +13057,6 @@
 #else
   if (!HasSource() || !token_pos.IsReal()) return -1;
   auto const zone = Thread::Current()->zone();
-  LookupSourceAndLineStarts(zone);
   // We don't explicitly save this data: Load the source and find it from there.
   const String& source = String::Handle(zone, Source());
   const intptr_t start = token_pos.Pos();
@@ -13129,7 +13082,6 @@
   // Line numbers are 1-indexed.
   if (line_number <= 0) return false;
   Zone* zone = Thread::Current()->zone();
-  LookupSourceAndLineStarts(zone);
   const TypedData& line_starts_data = TypedData::Handle(zone, line_starts());
   kernel::KernelLineStartsReader line_starts_reader(line_starts_data, zone);
   if (!line_starts_reader.TokenRangeAtLine(line_number, first_token_index,
@@ -13267,7 +13219,6 @@
   result.set_resolved_url(
       String::Handle(zone, Symbols::New(thread, resolved_url)));
   result.set_source(source);
-  NOT_IN_PRECOMPILED(result.SetLazyLookupSourceAndLineStarts(false));
   NOT_IN_PRECOMPILED(result.SetHasCachedMaxPosition(false));
   result.set_kernel_script_index(0);
   result.set_load_timestamp(
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index 58f6b9fa..0dfaa94 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -4862,7 +4862,6 @@
   StringPtr Source() const;
   bool IsPartOfDartColonLibrary() const;
 
-  void LookupSourceAndLineStarts(Zone* zone) const;
   GrowableObjectArrayPtr GenerateLineNumberArray() const;
 
   intptr_t line_offset() const { return 0; }
@@ -4949,7 +4948,6 @@
 #if !defined(DART_PRECOMPILED_RUNTIME)
   bool HasCachedMaxPosition() const;
 
-  void SetLazyLookupSourceAndLineStarts(bool value) const;
   void SetHasCachedMaxPosition(bool value) const;
   void SetCachedMaxPosition(intptr_t value) const;
 #endif  // !defined(DART_PRECOMPILED_RUNTIME)
diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc
index acb5886..3ea34ac 100644
--- a/runtime/vm/service.cc
+++ b/runtime/vm/service.cc
@@ -4934,7 +4934,6 @@
     // load the source before sending the response.
     if (obj->IsScript()) {
       const Script& script = Script::Cast(*obj);
-      script.LookupSourceAndLineStarts(thread->zone());
       if (!script.HasSource() && script.IsPartOfDartColonLibrary() &&
           Service::HasDartLibraryKernelForSources()) {
         const uint8_t* kernel_buffer = Service::dart_library_kernel();