Skip to content

Commit

Permalink
mbe::TokenTree: remove Lrc around Delimited and `SequenceRepeti…
Browse files Browse the repository at this point in the history
…tion`.
  • Loading branch information
nnethercote committed Apr 13, 2022
1 parent 75fd391 commit dd9028a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
7 changes: 3 additions & 4 deletions compiler/rustc_expand/src/mbe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ crate mod transcribe;
use metavar_expr::MetaVarExpr;
use rustc_ast::token::{self, NonterminalKind, Token, TokenKind};
use rustc_ast::tokenstream::DelimSpan;
use rustc_data_structures::sync::Lrc;
use rustc_span::symbol::Ident;
use rustc_span::Span;

Expand Down Expand Up @@ -64,13 +63,13 @@ enum KleeneOp {

/// Similar to `tokenstream::TokenTree`, except that `Sequence`, `MetaVar`, `MetaVarDecl`, and
/// `MetaVarExpr` are "first-class" token trees. Useful for parsing macros.
#[derive(Debug, Clone, PartialEq, Encodable, Decodable)]
#[derive(Debug, PartialEq, Encodable, Decodable)]
enum TokenTree {
Token(Token),
/// A delimited sequence, e.g. `($e:expr)` (RHS) or `{ $e }` (LHS).
Delimited(DelimSpan, Lrc<Delimited>),
Delimited(DelimSpan, Delimited),
/// A kleene-style repetition sequence, e.g. `$($e:expr)*` (RHS) or `$($e),*` (LHS).
Sequence(DelimSpan, Lrc<SequenceRepetition>),
Sequence(DelimSpan, SequenceRepetition),
/// e.g., `$var`.
MetaVar(Span, Ident),
/// e.g., `$var:expr`. Only appears on the LHS.
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use rustc_ast::{NodeId, DUMMY_NODE_ID};
use rustc_ast_pretty::pprust;
use rustc_attr::{self as attr, TransparencyError};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lrc;
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
use rustc_feature::Features;
use rustc_lint_defs::builtin::{
Expand Down Expand Up @@ -407,7 +406,7 @@ pub fn compile_declarative_macro(
let argument_gram = vec![
mbe::TokenTree::Sequence(
DelimSpan::dummy(),
Lrc::new(mbe::SequenceRepetition {
mbe::SequenceRepetition {
tts: vec![
mbe::TokenTree::MetaVarDecl(def.span, lhs_nm, tt_spec),
mbe::TokenTree::token(token::FatArrow, def.span),
Expand All @@ -419,20 +418,20 @@ pub fn compile_declarative_macro(
)),
kleene: mbe::KleeneToken::new(mbe::KleeneOp::OneOrMore, def.span),
num_captures: 2,
}),
},
),
// to phase into semicolon-termination instead of semicolon-separation
mbe::TokenTree::Sequence(
DelimSpan::dummy(),
Lrc::new(mbe::SequenceRepetition {
mbe::SequenceRepetition {
tts: vec![mbe::TokenTree::token(
if macro_rules { token::Semi } else { token::Comma },
def.span,
)],
separator: None,
kleene: mbe::KleeneToken::new(mbe::KleeneOp::ZeroOrMore, def.span),
num_captures: 0,
}),
},
),
];
// Convert it into `MatcherLoc` form.
Expand Down
13 changes: 3 additions & 10 deletions compiler/rustc_expand/src/mbe/quoted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::edition::Edition;
use rustc_span::{Span, SyntaxContext};

use rustc_data_structures::sync::Lrc;

const VALID_FRAGMENT_NAMES_MSG: &str = "valid fragment specifiers are \
`ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, \
`literal`, `path`, `meta`, `tt`, `item` and `vis`";
Expand Down Expand Up @@ -213,12 +211,7 @@ fn parse_tree(
if parsing_patterns { count_metavar_decls(&sequence) } else { 0 };
TokenTree::Sequence(
delim_span,
Lrc::new(SequenceRepetition {
tts: sequence,
separator,
kleene,
num_captures,
}),
SequenceRepetition { tts: sequence, separator, kleene, num_captures },
)
}

Expand Down Expand Up @@ -269,10 +262,10 @@ fn parse_tree(
// descend into the delimited set and further parse it.
tokenstream::TokenTree::Delimited(span, delim, tts) => TokenTree::Delimited(
span,
Lrc::new(Delimited {
Delimited {
delim,
tts: parse(tts, parsing_patterns, sess, node_id, features, edition),
}),
},
),
}
}
Expand Down

0 comments on commit dd9028a

Please sign in to comment.