rust-lang / rust-lang/rust-analyzer

Eagerly expand all macros?

Open
#9,933 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-Architecture
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

Today, we use lazy model of macro expansion, and expand macros only when we "need to". In practice, this means that top-level macros are expanded when we look into the crate, and macros in bodies are expanded when we look into the body during lowering.

An alternative solution is to eagerly expand all the macros, and have an expand_crate query, which is run after crate def-map. There are at least two reasons why such eager expansion might be beneficial.

  1. It allows for correct (in some sense) find usages: https://github.com/rust-analyzer/rust-analyzer/issues/7427
  2. It works better for cases where expanded code includes some other codes (mods or inlcudes inside macros, procedural macros that use spans from external files)

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 tracing the lazy macro-expansion flow described in the issue, including crate def-map lookup and body lowering. Evaluate the proposed expand_crate query against find-usages and macros containing modules or includes; done requires an agreed architectural direction, since no files or tests are named.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Refactor
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.