rust-lang / rust-lang/rust

Simple `proc_macro::Span` operations should not require going through bridge

Open
#149,331 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-proc-macros C-enhancement T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Motivation

This was mentioned in #149229 and since there doesn't seem to be a dedicated issue tracking this, I decided to make one.

Essentially, Span::join is a pretty key operation on spans: the very simple example of combining the open and close spans for a group to get the span of the whole group applies beyond groups to all sorts of parser implementations. The fact that this is not a trivial operation and requires going through the bridge means that it incurs a substantially larger performance penalty than you'd expect.

Potential Solutions

I decided to keep the problem statement intentionally vague to ensure that the solution set is large enough to allow compromises between performance and compatibility. It's been proposed that the solution to this is to make Span have a set representation across bridges, but this isn't actually necessary to solve this problem: we could, for example, represent Span as an opaque "source" ID and a start and end index. To actually get information about what the source represents, e.g. a file or macro call site, or a concrete line/column number, you would still have to go through the bridge. But, simple operations like joining spans could easily be done without having to go through the bridge.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the proc_macro::Span::join operation and the discussion in issue #149229. Determine which simple Span operations currently cross the bridge and compare the proposed representations, including a source ID with start and end indices. Done means an agreed implementation direction that reduces bridge overhead while preserving access to source and call-site information through the bridge.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.