Skip to content

Conversation

jonmeow
Copy link
Contributor

@jonmeow jonmeow commented Jun 9, 2025

Split out TokenInfo to be able to easily write using ValueType = TokenInfo; on TokenIndex. Also fixes a small type issue on ValueStore that affected mapped_iterator behavior when writing old_tokens_it->first < next_offset.

@github-actions github-actions bot requested a review from zygoloid June 9, 2025 19:00
Copy link
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

Comment on lines +159 to +162
// For `it->val`, writing `const std::pair` is required; otherwise
// `mapped_iterator` incorrectly infers the pointer type for `PointerProxy`.
// NOLINTNEXTLINE(readability-const-return-type)
auto index_to_id = [&](int32_t i) -> const std::pair<IdT, ConstRefType> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm understanding this correctly, the problem is that the operator-> here is declared const, which means that &R is a const pair* but the return type is non-const pair*. I wonder if upstream would take a patch removing the const there? (And from ReferenceProxy which has the same problem I think.)

In any case, we shouldn't block on fixing this upstream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that sounds right. I wasn't confident that modifying the proxy types to remove the const would be well-received though, because maybe const-ness is important?


namespace Carbon::Lex {

// Storage for the information about a specific token in the buffer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth mentioning in this comment that this type is an implementation detail of the TokenizedBuffer and Lexer classes and is not public API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, though it feels a little weird -- I don't think we do that elsewhere, even in something like NumericLiteral

@jonmeow jonmeow enabled auto-merge June 9, 2025 21:56
@jonmeow jonmeow added this pull request to the merge queue Jun 9, 2025
Merged via the queue into carbon-language:trunk with commit 6683cf3 Jun 9, 2025
8 checks passed
@jonmeow jonmeow deleted the token-info-range branch June 9, 2025 22:55
bricknerb pushed a commit to bricknerb/carbon-lang that referenced this pull request Jun 11, 2025
Split out `TokenInfo` to be able to easily write `using ValueType =
TokenInfo;` on `TokenIndex`. Also fixes a small type issue on
`ValueStore` that affected `mapped_iterator` behavior when writing
`old_tokens_it->first < next_offset`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants