Skip to content

Conversation

@petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Jan 22, 2026

An implementation for the suggestion from #150982 (comment).

I won't even benchmark it, just submitting for history.
The problem of having both packed and unpacked spans in different places is real, but this isn't the way to solve it, see some thoughts in the next comment.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 22, 2026
@petrochenkov
Copy link
Contributor Author

The Span structure currently packs its data to keep the structure size small (64 bit).
This is needed because we have a number of data structures keeping thousands (millions?) of spans - token streams, AST, HIR, etc.
If the Span size increases, then we see perf regressions across the board, this was measured when the current size of Span was introduced (todo - find the relevant PR).

The downside is that we need to unpack the span to read some data from it, and pack it back if we need a modifying operation.
This may be slow, #150982 (comment) shows improvements from not doing span packing-unpacking on some hot code from name resolution.

Ideally we would keep spans packed only in the necessary data structures, but worked with unpacked spans in all places where we need to execute some logic on them. Individual larger unpacked spans on stack don't pose any problems.

Name resolution in particular needs a several "partially unpacked indentifier" structures, to work with this in both fast and principled way.

For example, something like

struct Macros20NormalizedIdentKey {
  name: Symbol,
  ctxt: Macros20NormalizedSyntaxContext, // unpacked normalized syntax context
}

which would serve as a key for names planted in modules (and other "name containers" like preludes).
It would (eventually) allow to get rid of hacks in the PartialEq and Hash implementations for Ident, which ignore span locations inside idents.

Also something like

struct AnotherIdent {
  name: Symbol,
  ctxt: SyntaxContext, // unpacked possibly normalized syntax context
                      // loses information compared to original span during normalization
                      // so it's incorrect to use it for edition checks, and suboptimal to use it for diagnostics (macro backtrace will be incomplete)
  orig_span: Span, // original non-normalized identifier span, used for diagnostics and edition checks
}

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 22, 2026
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
REPOSITORY                                   TAG       IMAGE ID       CREATED       SIZE
ghcr.io/dependabot/dependabot-updater-core   latest    63ba4a2ff346   13 days ago   775MB
=> Removing docker images...
Deleted Images:
untagged: ghcr.io/dependabot/dependabot-updater-core:latest
untagged: ghcr.io/dependabot/dependabot-updater-core@sha256:830c840ea4b8c27b6919bdd47c017030adeb538f226e1cdfd386490a622b9218
deleted: sha256:63ba4a2ff3467a98ac6c8610fece2cdc9893e2af6c18111e57618f8949749b82
deleted: sha256:77617fa265a7311b1c0502e01ff6157d25228d91f6cddc21d7901eb440d0adee
deleted: sha256:0bd8abdbb1f7c0453b4bc76cce6ecf0a3b9e4b5d0c8ceeb63652e91a63cab4a1
deleted: sha256:4e9913397e051a70593edc1662de159778ce1bf65132295639da0e119913b53f
deleted: sha256:3e54edb2fef4b1c1393a2928bfa1017c22cc578f5f3eef677580662e8d2e79ea
---
Command `git clone --depth=1 https://github.com/rust-lang-nursery/rust-toolstate rust-toolstate` failed with exit code 128
Created at: src/bootstrap/src/core/build_steps/toolstate.rs:314:5
Executed at: src/bootstrap/src/core/build_steps/toolstate.rs:319:10

Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:00:08
  local time: Thu Jan 22 14:08:06 UTC 2026
  network time: Thu, 22 Jan 2026 14:08:07 GMT
##[error]Process completed with exit code 1.
##[group]Run echo "disk usage:"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants