Skip to content

Commit 8b67fcb

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm] Cleanup script tags
VM creates Script objects with kKernelTag only, so this CL cleans up all uses of script tags and Script::kind() along with code which is no longer reachable. Change-Id: Ia765e7757264aa614e18eddd16d21937f855c129 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123889 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
1 parent ebc6340 commit 8b67fcb

File tree

13 files changed

+64
-161
lines changed

13 files changed

+64
-161
lines changed

runtime/lib/mirrors.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,10 +1697,8 @@ DEFINE_NATIVE_ENTRY(DeclarationMirror_location, 0, 1) {
16971697
return Instance::null(); // No source.
16981698
}
16991699
const Array& scripts = Array::Handle(zone, lib.LoadedScripts());
1700-
for (intptr_t i = 0; i < scripts.Length(); i++) {
1701-
script ^= scripts.At(i);
1702-
if (script.kind() == RawScript::kLibraryTag) break;
1703-
}
1700+
ASSERT(scripts.Length() > 0);
1701+
script ^= scripts.At(scripts.Length() - 1);
17041702
ASSERT(!script.IsNull());
17051703
const String& uri = String::Handle(zone, script.url());
17061704
return CreateSourceLocation(uri, 1, 1);

runtime/vm/clustered_snapshot.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ class ScriptSerializationCluster : public SerializationCluster {
11001100
WriteFromTo(script);
11011101
s->Write<int32_t>(script->ptr()->line_offset_);
11021102
s->Write<int32_t>(script->ptr()->col_offset_);
1103-
s->Write<uint8_t>(script->ptr()->kind_and_tags_);
1103+
s->Write<uint8_t>(script->ptr()->flags_);
11041104
s->Write<int32_t>(script->ptr()->kernel_script_index_);
11051105
}
11061106
}
@@ -1133,7 +1133,7 @@ class ScriptDeserializationCluster : public DeserializationCluster {
11331133
ReadFromTo(script);
11341134
script->ptr()->line_offset_ = d->Read<int32_t>();
11351135
script->ptr()->col_offset_ = d->Read<int32_t>();
1136-
script->ptr()->kind_and_tags_ = d->Read<uint8_t>();
1136+
script->ptr()->flags_ = d->Read<uint8_t>();
11371137
script->ptr()->kernel_script_index_ = d->Read<int32_t>();
11381138
script->ptr()->load_timestamp_ = 0;
11391139
}

runtime/vm/compiler/frontend/bytecode_reader.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ RawObject* BytecodeReaderHelper::ReadObjectContents(uint32_t header) {
15401540
ReadSourceFile(uri, bytecode_component_->GetSourceFilesOffset() +
15411541
reader_.ReadUInt());
15421542
} else {
1543-
script = Script::New(uri, Object::null_string(), RawScript::kKernelTag);
1543+
script = Script::New(uri, Object::null_string());
15441544
}
15451545
script.set_kernel_program_info(H.GetKernelProgramInfo());
15461546
return script.raw();
@@ -1910,8 +1910,8 @@ RawScript* BytecodeReaderHelper::ReadSourceFile(const String& uri,
19101910
source = ReadString(/* is_canonical = */ false);
19111911
}
19121912

1913-
const Script& script = Script::Handle(
1914-
Z, Script::New(import_uri, uri, source, RawScript::kKernelTag));
1913+
const Script& script =
1914+
Script::Handle(Z, Script::New(import_uri, uri, source));
19151915
script.set_line_starts(line_starts);
19161916

19171917
if (source.IsNull() && line_starts.IsNull()) {

runtime/vm/debugger.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,6 @@ void ActivationFrame::ExtractTokenPositionFromAsyncClosure() {
10531053
}
10541054

10551055
ASSERT(!IsInterpreted());
1056-
ASSERT(script.kind() == RawScript::kKernelTag);
10571056
const intptr_t await_jump_var = GetAwaitJumpVariable();
10581057
if (await_jump_var < 0) {
10591058
return;
@@ -3063,7 +3062,6 @@ TokenPosition Debugger::ResolveBreakpointPos(bool in_bytecode,
30633062
const TokenPosition begin_pos = best_fit_pos;
30643063

30653064
TokenPosition end_of_line_pos;
3066-
ASSERT(script.kind() == RawScript::kKernelTag);
30673065
if (best_line == -1) {
30683066
script.GetTokenLocation(begin_pos, &best_line, NULL);
30693067
}
@@ -4379,7 +4377,6 @@ bool Debugger::IsAtAsyncJump(ActivationFrame* top_frame) {
43794377
}
43804378
ASSERT(!top_frame->IsInterpreted());
43814379
const Script& script = Script::Handle(zone, top_frame->SourceScript());
4382-
ASSERT(script.kind() == RawScript::kKernelTag);
43834380
const auto& yield_positions = GrowableObjectArray::Handle(
43844381
zone, script.GetYieldPositions(top_frame->function()));
43854382
// No yield statements

runtime/vm/exceptions.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -822,11 +822,7 @@ void Exceptions::CreateAndThrowTypeError(TokenPosition location,
822822
intptr_t column = -1;
823823
ASSERT(!script.IsNull());
824824
if (location.IsReal()) {
825-
if (script.HasSource() || script.kind() == RawScript::kKernelTag) {
826-
script.GetTokenLocation(location, &line, &column);
827-
} else {
828-
script.GetTokenLocation(location, &line, NULL);
829-
}
825+
script.GetTokenLocation(location, &line, &column);
830826
}
831827
// Initialize '_url', '_line', and '_column' arguments.
832828
args.SetAt(0, String::Handle(zone, script.url()));

runtime/vm/kernel_loader.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,7 @@ RawScript* KernelLoader::LoadScriptAt(intptr_t index,
20592059
for (intptr_t i = 0; i < libs.Length(); i++) {
20602060
lib ^= libs.At(i);
20612061
script = lib.LookupScript(uri_string, /* useResolvedUri = */ true);
2062-
if (!script.IsNull() && script.kind() == RawScript::kKernelTag) {
2062+
if (!script.IsNull()) {
20632063
sources = script.Source();
20642064
line_starts = script.line_starts();
20652065
break;
@@ -2071,8 +2071,7 @@ RawScript* KernelLoader::LoadScriptAt(intptr_t index,
20712071
}
20722072

20732073
const Script& script =
2074-
Script::Handle(Z, Script::New(import_uri_string, uri_string, sources,
2075-
RawScript::kKernelTag));
2074+
Script::Handle(Z, Script::New(import_uri_string, uri_string, sources));
20762075
script.set_kernel_script_index(index);
20772076
script.set_kernel_program_info(kernel_program_info_);
20782077
script.set_line_starts(line_starts);

runtime/vm/object.cc

Lines changed: 42 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -8067,43 +8067,36 @@ RawString* Function::GetSource() const {
80678067
Zone* zone = Thread::Current()->zone();
80688068
const Script& func_script = Script::Handle(zone, script());
80698069

8070-
if (func_script.kind() == RawScript::kKernelTag) {
8071-
intptr_t from_line;
8072-
intptr_t from_col;
8073-
intptr_t to_line;
8074-
intptr_t to_col;
8075-
intptr_t to_length;
8076-
func_script.GetTokenLocation(token_pos(), &from_line, &from_col);
8077-
func_script.GetTokenLocation(end_token_pos(), &to_line, &to_col,
8078-
&to_length);
8079-
8080-
if (to_length == 1) {
8081-
// Handle special cases for end tokens of closures (where we exclude the
8082-
// last token):
8083-
// (1) "foo(() => null, bar);": End token is `,', but we don't print it.
8084-
// (2) "foo(() => null);": End token is ')`, but we don't print it.
8085-
// (3) "var foo = () => null;": End token is `;', but in this case the
8086-
// token semicolon belongs to the assignment so we skip it.
8087-
const String& src = String::Handle(func_script.Source());
8088-
if (src.IsNull() || src.Length() == 0) {
8089-
return Symbols::OptimizedOut().raw();
8090-
}
8091-
uint16_t end_char = src.CharAt(end_token_pos().value());
8092-
if ((end_char == ',') || // Case 1.
8093-
(end_char == ')') || // Case 2.
8094-
(end_char == ';' &&
8095-
String::Handle(zone, name())
8096-
.Equals("<anonymous closure>"))) { // Case 3.
8097-
to_length = 0;
8098-
}
8099-
}
8070+
intptr_t from_line;
8071+
intptr_t from_col;
8072+
intptr_t to_line;
8073+
intptr_t to_col;
8074+
intptr_t to_length;
8075+
func_script.GetTokenLocation(token_pos(), &from_line, &from_col);
8076+
func_script.GetTokenLocation(end_token_pos(), &to_line, &to_col, &to_length);
81008077

8101-
return func_script.GetSnippet(from_line, from_col, to_line,
8102-
to_col + to_length);
8078+
if (to_length == 1) {
8079+
// Handle special cases for end tokens of closures (where we exclude the
8080+
// last token):
8081+
// (1) "foo(() => null, bar);": End token is `,', but we don't print it.
8082+
// (2) "foo(() => null);": End token is ')`, but we don't print it.
8083+
// (3) "var foo = () => null;": End token is `;', but in this case the
8084+
// token semicolon belongs to the assignment so we skip it.
8085+
const String& src = String::Handle(func_script.Source());
8086+
if (src.IsNull() || src.Length() == 0) {
8087+
return Symbols::OptimizedOut().raw();
8088+
}
8089+
uint16_t end_char = src.CharAt(end_token_pos().value());
8090+
if ((end_char == ',') || // Case 1.
8091+
(end_char == ')') || // Case 2.
8092+
(end_char == ';' && String::Handle(zone, name())
8093+
.Equals("<anonymous closure>"))) { // Case 3.
8094+
to_length = 0;
8095+
}
81038096
}
81048097

8105-
UNREACHABLE();
8106-
return String::null();
8098+
return func_script.GetSnippet(from_line, from_col, to_line,
8099+
to_col + to_length);
81078100
}
81088101

81098102
// Construct fingerprint from token stream. The token stream contains also
@@ -9518,7 +9511,7 @@ void Script::LookupSourceAndLineStarts(Zone* zone) const {
95189511
for (intptr_t i = 0; i < libs.Length(); i++) {
95199512
lib ^= libs.At(i);
95209513
script = lib.LookupScript(uri, /* useResolvedUri = */ true);
9521-
if (!script.IsNull() && script.kind() == RawScript::kKernelTag) {
9514+
if (!script.IsNull()) {
95229515
const auto& source = String::Handle(zone, script.Source());
95239516
const auto& line_starts = TypedData::Handle(zone, script.line_starts());
95249517
if (!source.IsNull() || !line_starts.IsNull()) {
@@ -9534,7 +9527,6 @@ void Script::LookupSourceAndLineStarts(Zone* zone) const {
95349527
}
95359528

95369529
RawGrowableObjectArray* Script::GenerateLineNumberArray() const {
9537-
ASSERT(kind() == RawScript::kKernelTag);
95389530
Zone* zone = Thread::Current()->zone();
95399531
const GrowableObjectArray& info =
95409532
GrowableObjectArray::Handle(zone, GrowableObjectArray::New());
@@ -9589,25 +9581,6 @@ RawGrowableObjectArray* Script::GenerateLineNumberArray() const {
95899581
return info.raw();
95909582
}
95919583

9592-
const char* Script::GetKindAsCString() const {
9593-
switch (kind()) {
9594-
case RawScript::kScriptTag:
9595-
return "script";
9596-
case RawScript::kLibraryTag:
9597-
return "library";
9598-
case RawScript::kSourceTag:
9599-
return "source";
9600-
case RawScript::kEvaluateTag:
9601-
return "evaluate";
9602-
case RawScript::kKernelTag:
9603-
return "kernel";
9604-
default:
9605-
UNIMPLEMENTED();
9606-
}
9607-
UNREACHABLE();
9608-
return NULL;
9609-
}
9610-
96119584
void Script::set_url(const String& value) const {
96129585
StorePointer(&raw_ptr()->url_, value.raw());
96139586
}
@@ -9662,31 +9635,25 @@ RawTypedData* Script::line_starts() const {
96629635
RawArray* Script::debug_positions() const {
96639636
#if !defined(DART_PRECOMPILED_RUNTIME)
96649637
Array& debug_positions_array = Array::Handle(raw_ptr()->debug_positions_);
9665-
if (debug_positions_array.IsNull() && kind() == RawScript::kKernelTag) {
9638+
if (debug_positions_array.IsNull()) {
96669639
// This is created lazily. Now we need it.
96679640
kernel::CollectTokenPositionsFor(*this);
96689641
}
96699642
#endif // !defined(DART_PRECOMPILED_RUNTIME)
96709643
return raw_ptr()->debug_positions_;
96719644
}
96729645

9673-
void Script::set_kind(RawScript::Kind value) const {
9674-
set_kind_and_tags(
9675-
RawScript::KindBits::update(value, raw_ptr()->kind_and_tags_));
9676-
}
9677-
9678-
void Script::set_kind_and_tags(uint8_t value) const {
9679-
StoreNonPointer(&raw_ptr()->kind_and_tags_, value);
9646+
void Script::set_flags(uint8_t value) const {
9647+
StoreNonPointer(&raw_ptr()->flags_, value);
96809648
}
96819649

96829650
void Script::SetLazyLookupSourceAndLineStarts(bool value) const {
9683-
set_kind_and_tags(RawScript::LazyLookupSourceAndLineStartsBit::update(
9684-
value, raw_ptr()->kind_and_tags_));
9651+
set_flags(RawScript::LazyLookupSourceAndLineStartsBit::update(
9652+
value, raw_ptr()->flags_));
96859653
}
96869654

96879655
bool Script::IsLazyLookupSourceAndLineStarts() const {
9688-
return RawScript::LazyLookupSourceAndLineStartsBit::decode(
9689-
raw_ptr()->kind_and_tags_);
9656+
return RawScript::LazyLookupSourceAndLineStartsBit::decode(raw_ptr()->flags_);
96909657
}
96919658

96929659
void Script::set_load_timestamp(int64_t value) const {
@@ -9715,31 +9682,12 @@ intptr_t Script::GetTokenLineUsingLineStarts(
97159682
return 0;
97169683
}
97179684

9718-
if (kind() == RawScript::kKernelTag) {
97199685
#if !defined(DART_PRECOMPILED_RUNTIME)
9720-
kernel::KernelLineStartsReader line_starts_reader(line_starts_data, zone);
9721-
return line_starts_reader.LineNumberForPosition(target_token_pos.value());
9686+
kernel::KernelLineStartsReader line_starts_reader(line_starts_data, zone);
9687+
return line_starts_reader.LineNumberForPosition(target_token_pos.value());
97229688
#else
9723-
return 0;
9689+
return 0;
97249690
#endif // !defined(DART_PRECOMPILED_RUNTIME)
9725-
} else {
9726-
ASSERT(line_starts_data.Length() > 0);
9727-
intptr_t offset = target_token_pos.Pos();
9728-
intptr_t min = 0;
9729-
intptr_t max = line_starts_data.Length() - 1;
9730-
9731-
// Binary search to find the line containing this offset.
9732-
while (min < max) {
9733-
int midpoint = (max - min + 1) / 2 + min;
9734-
int32_t token_pos = line_starts_data.GetInt32(midpoint * 4);
9735-
if (token_pos > offset) {
9736-
max = midpoint - 1;
9737-
} else {
9738-
min = midpoint;
9739-
}
9740-
}
9741-
return min + 1; // Line numbers start at 1.
9742-
}
97439691
}
97449692

97459693
#if !defined(DART_PRECOMPILED_RUNTIME)
@@ -9767,7 +9715,6 @@ void Script::GetTokenLocation(TokenPosition token_pos,
97679715
ASSERT(line != NULL);
97689716
Zone* zone = Thread::Current()->zone();
97699717

9770-
ASSERT(kind() == RawScript::kKernelTag);
97719718
LookupSourceAndLineStarts(zone);
97729719
if (line_starts() == TypedData::null()) {
97739720
// Scripts in the AOT snapshot do not have a line starts array.
@@ -9806,7 +9753,6 @@ void Script::GetTokenLocation(TokenPosition token_pos,
98069753
void Script::TokenRangeAtLine(intptr_t line_number,
98079754
TokenPosition* first_token_index,
98089755
TokenPosition* last_token_index) const {
9809-
ASSERT(kind() == RawScript::kKernelTag);
98109756
ASSERT(first_token_index != NULL && last_token_index != NULL);
98119757
ASSERT(line_number > 0);
98129758

@@ -9944,16 +9890,13 @@ RawScript* Script::New() {
99449890
return reinterpret_cast<RawScript*>(raw);
99459891
}
99469892

9947-
RawScript* Script::New(const String& url,
9948-
const String& source,
9949-
RawScript::Kind kind) {
9950-
return Script::New(url, url, source, kind);
9893+
RawScript* Script::New(const String& url, const String& source) {
9894+
return Script::New(url, url, source);
99519895
}
99529896

99539897
RawScript* Script::New(const String& url,
99549898
const String& resolved_url,
9955-
const String& source,
9956-
RawScript::Kind kind) {
9899+
const String& source) {
99579900
Thread* thread = Thread::Current();
99589901
Zone* zone = thread->zone();
99599902
const Script& result = Script::Handle(zone, Script::New());
@@ -9962,8 +9905,7 @@ RawScript* Script::New(const String& url,
99629905
String::Handle(zone, Symbols::New(thread, resolved_url)));
99639906
result.set_source(source);
99649907
result.SetLocationOffset(0, 0);
9965-
result.set_kind_and_tags(0);
9966-
result.set_kind(kind);
9908+
result.set_flags(0);
99679909
result.set_kernel_script_index(0);
99689910
result.set_load_timestamp(
99699911
FLAG_remove_script_timestamps_for_test ? 0 : OS::GetCurrentTimeMillis());
@@ -22009,11 +21951,7 @@ static void PrintStackTraceFrame(Zone* zone,
2200921951
line = token_pos.value();
2201021952
} else {
2201121953
if (!script.IsNull() && token_pos.IsSourcePosition()) {
22012-
if (script.HasSource() || script.kind() == RawScript::kKernelTag) {
22013-
script.GetTokenLocation(token_pos.SourcePosition(), &line, &column);
22014-
} else {
22015-
script.GetTokenLocation(token_pos.SourcePosition(), &line, NULL);
22016-
}
21954+
script.GetTokenLocation(token_pos.SourcePosition(), &line, &column);
2201721955
}
2201821956
}
2201921957

runtime/vm/object.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3904,11 +3904,6 @@ class Script : public Object {
39043904
void LookupSourceAndLineStarts(Zone* zone) const;
39053905
RawGrowableObjectArray* GenerateLineNumberArray() const;
39063906

3907-
RawScript::Kind kind() const {
3908-
return RawScript::KindBits::decode(raw_ptr()->kind_and_tags_);
3909-
}
3910-
3911-
const char* GetKindAsCString() const;
39123907
intptr_t line_offset() const { return raw_ptr()->line_offset_; }
39133908
intptr_t col_offset() const { return raw_ptr()->col_offset_; }
39143909

@@ -3973,14 +3968,11 @@ class Script : public Object {
39733968
return RoundedAllocationSize(sizeof(RawScript));
39743969
}
39753970

3976-
static RawScript* New(const String& url,
3977-
const String& source,
3978-
RawScript::Kind kind);
3971+
static RawScript* New(const String& url, const String& source);
39793972

39803973
static RawScript* New(const String& url,
39813974
const String& resolved_url,
3982-
const String& source,
3983-
RawScript::Kind kind);
3975+
const String& source);
39843976

39853977
#if !defined(DART_PRECOMPILED_RUNTIME)
39863978
void LoadSourceFromKernel(const uint8_t* kernel_buffer,
@@ -3993,8 +3985,7 @@ class Script : public Object {
39933985
private:
39943986
void set_resolved_url(const String& value) const;
39953987
void set_source(const String& value) const;
3996-
void set_kind(RawScript::Kind value) const;
3997-
void set_kind_and_tags(uint8_t value) const;
3988+
void set_flags(uint8_t value) const;
39983989
void set_load_timestamp(int64_t value) const;
39993990
RawArray* debug_positions() const;
40003991

0 commit comments

Comments
 (0)