Skip to content

Commit f6e4b77

Browse files
sstricklcommit-bot@chromium.org
authored andcommitted
[vm] Remove the only cases where TokenPositions are mutated.
The Next() method on TokenPositions used to increment the internal value_ field, but now creates a new TokenPosition with value_ + 1. There are only three places this is used: * Getting the token position after the end token position for implicit closure functions in the scope builder. * Getting the token position after the end token position for variable declarations in the scope builder. * Iterating over the token positions on a single source line in the debugger. So the overhead of creating new TokenPositions vs. mutating the original should be limited, compared to the benefit of being able to assume TokenPosition values are constant once created. There's too much dependence on the copy and copy assignment operators due to the previous possibility of mutation to make the internal field constant at the moment without much more sweeping changes, unfortunately. Also remove the copy assignment in initializing TokenPosition constants. TEST=Tested using existing tests on trybots. Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-linux-release-x64-try,vm-kernel-nnbd-linux-release-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-release-x64-try,vm-kernel-linux-product-x64-try,vm-kernel-precomp-linux-product-x64-try Change-Id: Ie18b7f45bd9c6a43647ecd189330d91a4dff373b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174922 Commit-Queue: Tess Strickland <sstrickl@google.com> Reviewed-by: Clement Skau <cskau@google.com>
1 parent a9d212b commit f6e4b77

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

runtime/vm/compiler/frontend/scope_builder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ void ScopeBuilder::VisitVariableDeclaration() {
12741274
// debuggable position in the initializer.
12751275
TokenPosition end_position = helper_.reader_.max_position();
12761276
if (end_position.IsReal()) {
1277-
end_position.Next();
1277+
end_position = end_position.Next();
12781278
}
12791279
LocalVariable* variable =
12801280
MakeVariable(helper.position_, end_position, name, type);

runtime/vm/debugger.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3033,7 +3033,7 @@ BreakpointLocation* Debugger::BreakpointLocationAtLineCol(
30333033
while ((loc == NULL) && (first_token_idx <= last_token_idx)) {
30343034
loc = SetBreakpoint(script, first_token_idx, last_token_idx, line_number,
30353035
column_number, Function::Handle());
3036-
first_token_idx.Next();
3036+
first_token_idx = first_token_idx.Next();
30373037
}
30383038
if ((loc == NULL) && FLAG_verbose_debug) {
30393039
OS::PrintErr("No executable code at line %" Pd " in '%s'\n", line_number,

runtime/vm/token_position.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ bool TokenPosition::IsSynthetic() const {
2727
}
2828

2929
#define DEFINE_VALUES(name, value) \
30-
const TokenPosition TokenPosition::k##name = TokenPosition(value);
30+
const TokenPosition TokenPosition::k##name(value);
3131
SENTINEL_TOKEN_DESCRIPTORS(DEFINE_VALUES);
3232
#undef DEFINE_VALUES
33-
const TokenPosition TokenPosition::kMinSource = TokenPosition(kMinSourcePos);
33+
const TokenPosition TokenPosition::kMinSource(kMinSourcePos);
3434

35-
const TokenPosition TokenPosition::kMaxSource = TokenPosition(kMaxSourcePos);
35+
const TokenPosition TokenPosition::kMaxSource(kMaxSourcePos);
3636

3737
const char* TokenPosition::ToCString() const {
3838
switch (value_) {

runtime/vm/token_position.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ class TokenPosition {
9595
// Encode for writing into a snapshot.
9696
int32_t SnapshotEncode();
9797

98-
// Increment the token position.
98+
// Given a real token position, returns the next real token position.
9999
TokenPosition Next() {
100100
ASSERT(IsReal());
101-
value_++;
102-
return *this;
101+
return TokenPosition(value_ + 1);
103102
}
104103

105104
// The raw value.

0 commit comments

Comments
 (0)