GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-153569: return token spans and unify decoded source storage by pablogsal · Pull Request #156482 · python/cpython

Conversation

@pablogsal

@pablogsal pablogsal commented Aug 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Return tokenizer tokens as logical source spans with start/end locations, and give all decoded input one owner in SourceText.

File and readline input discard consumed windows while advancing a logical base offset. Discard reuses the allocation and resets line metadata; prepared and interactive input retain their source. The separate streaming buffer allocation is removed. This prerequisite still rebases scanner pointers around append; #156654 replaces those pointers with offsets.

Debug source growth forces relocation. Tests cover f-/t-string growth in both token modes, interactive multiline input, discard/reuse, implicit-line metadata reset, and offset limits.

This follows #156472. The rest of the stack is #156484, then #156654.

  • Issue: Base the tokenizer API on source offsets #153569

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot mentioned this pull request Aug 27, 2026
Base the tokenizer API on source offsets #153569
Open
@pablogsal pablogsal mentioned this pull request Aug 27, 2026
gh-153569: centralize formatted-string state and source spans #156484
Merged
@pablogsal

pablogsal commented Aug 27, 2026

Copy link
Copy Markdown
Member Author

Do not review until #156472 lands.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal pablogsal added the skip news label Aug 27, 2026
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-offset-state branch from dddc133 to 1753605 Compare August 28, 2026 15:32
@pablogsal

pablogsal commented Aug 28, 2026

Copy link
Copy Markdown
Member Author

#156472 has landed; this is rebased on it now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-offset-state branch from 1753605 to 8bd1d3a Compare August 28, 2026 16:24
@pablogsal pablogsal changed the title gh-153569: move tokenizer state to source offsets gh-153569: drive tokenizer input through source offsets Aug 28, 2026
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-offset-state branch from 8bd1d3a to c10fd82 Compare August 28, 2026 18:08
@pablogsal pablogsal changed the title gh-153569: drive tokenizer input through source offsets gh-153569: return tokenizer tokens as source spans Aug 28, 2026
linakhan470-cell
linakhan470-cell reviewed Aug 28, 2026
View reviewed changes

@linakhan470-cell linakhan470-cell left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

183

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pablogsal
pablogsal marked this pull request as ready for review August 28, 2026 21:15
@pablogsal
pablogsal requested a review from lysnikolaou as a code owner August 28, 2026 21:15
@bedevere-app bedevere-app Bot added the awaiting core review label Aug 28, 2026
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-offset-state branch 3 times, most recently from 150ee6a to f134e81 Compare August 30, 2026 16:10
@pablogsal pablogsal changed the title gh-153569: return tokenizer tokens as source spans gh-153569: return token spans and unify decoded source storage Sep 5, 2026
pablogsal added 6 commits September 5, 2026 20:24
@pablogsal
pythongh-153569: bound tokenizer input storage
44ef2d1
File and readline tokenizers keep every byte they read because the lexer owns
buffer growth and repairs its pointers after reallocations. Long inputs
therefore grow tokenizer memory with the entire source.

Let the reader reuse a bounded input window when no token or formatted string
needs older bytes. Track the absolute offset of that window and save pointer
offsets only when backing storage moves.
@pablogsal
pythongh-153569: return tokenizer tokens as source spans
f381082
Tokenizer results expose pointers into the active input buffer. That ties every
consumer to the buffer lifetime and prevents the reader from reusing older
storage.

Return logical source spans with their start and end locations instead. Pegen
and `_tokenize` materialize a short-lived view before requesting another token,
and the tokenizer no longer keeps a second end pointer for the last token.
@pablogsal
pythongh-153569: enforce tokenizer buffer view lifetimes
b60cc04
@pablogsal
pythongh-153569: Unify decoded tokenizer storage ownership
2bdef78
@pablogsal
pythongh-153569: Avoid overflow when sizing implicit line flags
27c3d73
@pablogsal
Remove stale tokenizer buffer ownership comment
6117ae3
@pablogsal
pablogsal force-pushed the gh-153569-tokenizer-offset-state branch from bf25f7b to 6117ae3 Compare September 5, 2026 19:52
@pablogsal
pablogsal merged commit 09117bc into python:main Sep 6, 2026
70 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pablogsal deleted the gh-153569-tokenizer-offset-state branch September 6, 2026 20:15
@bedevere-app bedevere-app Bot removed the awaiting core review label Sep 6, 2026
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
@pablogsal @clin1234
pythongh-153569: return token spans and unify decoded source storage (p…
14b465f
…ython#156482)

Represent token boundaries as logical source offsets with explicit start
and end locations, and adapt pegen and _tokenize to consume them.

Use SourceText to own decoded input across all reader modes. Streaming
readers discard consumed windows while preserving logical offsets and
reusing the allocation. Prepared and interactive input retain their source.

Force source relocation on growth in debug builds and add coverage for
formatted-string growth, interactive input, storage reuse, and offset
limits. Scanner positions remain pointers, rebased when storage moves.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner
1 more reviewer
@linakhan470-cell linakhan470-cell linakhan470-cell left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@pablogsal @linakhan470-cell
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.