Skip to content

Simplify LazyAttrTokenStream#127516

Merged
bors merged 3 commits intorust-lang:masterfrom
nnethercote:simplify-LazyAttrTokenStream
Apr 30, 2025
Merged

Simplify LazyAttrTokenStream#127516
bors merged 3 commits intorust-lang:masterfrom
nnethercote:simplify-LazyAttrTokenStream

Conversation

@nnethercote
Copy link
Copy Markdown
Contributor

@nnethercote nnethercote commented Jul 9, 2024

LazyAttrTokenStream is an unpleasant type: Lrc<Box<dyn ToAttrTokenStream>>. Why does it look like that?

  • There are two ToAttrTokenStream impls, one for the lazy case, and one for the case where we already have an AttrTokenStream.
  • The lazy case (LazyAttrTokenStreamImpl) is implemented in rustc_parse, but LazyAttrTokenStream is defined in rustc_ast, which does not depend on rustc_parse. The use of the trait lets rustc_ast implicitly depend on rustc_parse. This explains the dyn.
  • LazyAttrTokenStream must have a size_of as small as possible, because it's used in many AST nodes. This explains the Lrc<Box<_>>, which keeps it to one word. (It's required Lrc<dyn _> would be a fat pointer.)

This PR moves LazyAttrTokenStreamImpl (and a few other token stream things) from rustc_parse to rustc_ast. This lets us replace the ToAttrTokenStream trait with a two-variant enum and also remove the Box, changing LazyAttrTokenStream to Lrc<LazyAttrTokenStreamInner>. Plus it does a few cleanups.

r? @petrochenkov

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

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

7 participants