[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>
This commit is contained in:
Martin Kustermann 2023-07-11 13:29:33 +00:00 committed by Commit Queue
parent 48def8e49a
commit 9a909ac320
4 changed files with 8 additions and 65 deletions

View file

@ -206,7 +206,6 @@ static ArrayPtr AsSortedDuplicateFreeArray(GrowableArray<intptr_t>* source) {
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 @@ static void CollectKernelDataTokenPositions(
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 @@ static void CollectKernelDataTokenPositions(
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 @@ void CollectTokenPositionsFor(const Script& interesting_script) {
}
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 @@ void CollectTokenPositionsFor(const Script& interesting_script) {
}
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 @@ void CollectTokenPositionsFor(const Script& interesting_script) {
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 @@ void CollectTokenPositionsFor(const Script& interesting_script) {
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 @@ void CollectTokenPositionsFor(const Script& interesting_script) {
}
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 @@ void CollectTokenPositionsFor(const Script& interesting_script) {
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);

View file

@ -12866,44 +12866,11 @@ TypedDataPtr Script::kernel_string_offsets() const {
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 @@ TokenPosition Script::MaxPosition() const {
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 @@ ArrayPtr Script::debug_positions() const {
}
#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 @@ bool Script::GetTokenLocation(const TokenPosition& token_pos,
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 @@ intptr_t Script::GetTokenLength(const TokenPosition& token_pos) const {
#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 @@ bool Script::TokenRangeAtLine(intptr_t line_number,
// 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 @@ ScriptPtr Script::New(const String& url,
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(

View file

@ -4862,7 +4862,6 @@ class Script : public Object {
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 @@ class Script : public Object {
#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)

View file

@ -4934,7 +4934,6 @@ static bool GetHeapObjectCommon(Thread* thread,
// 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();