diff options
Diffstat (limited to 'compiler/rustc_expand/src')
| -rw-r--r-- | compiler/rustc_expand/src/base.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/build.rs | 52 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/expand.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/mbe/macro_rules.rs | 47 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/mbe/quoted.rs | 36 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/mbe/transcribe.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/proc_macro_server.rs | 6 | 
7 files changed, 105 insertions, 55 deletions
| diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 43feab94c01..819694d1cdc 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -3,6 +3,7 @@ use std::iter; use std::path::Component::Prefix; use std::path::{Path, PathBuf}; use std::rc::Rc; +use std::sync::Arc; use rustc_ast::attr::{AttributeExt, MarkedAttrs}; use rustc_ast::ptr::P; @@ -12,7 +13,7 @@ use rustc_ast::visit::{AssocCtxt, Visitor}; use rustc_ast::{self as ast, AttrVec, Attribute, HasAttrs, Item, NodeId, PatKind}; use rustc_attr_parsing::{self as attr, Deprecation, Stability}; use rustc_data_structures::fx::FxIndexMap; -use rustc_data_structures::sync::{self, Lrc}; +use rustc_data_structures::sync; use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, PResult}; use rustc_feature::Features; use rustc_lint_defs::{BufferedEarlyLint, RegisteredTools}; @@ -727,7 +728,7 @@ pub struct SyntaxExtension { /// Span of the macro definition. pub span: Span, /// List of unstable features that are treated as stable inside this macro. - pub allow_internal_unstable: Option<Lrc<[Symbol]>>, + pub allow_internal_unstable: Option<Arc<[Symbol]>>, /// The macro's stability info. pub stability: Option<Stability>, /// The macro's deprecation info. @@ -986,7 +987,7 @@ pub struct Indeterminate; pub struct DeriveResolution { pub path: ast::Path, pub item: Annotatable, - pub exts: Option<Lrc<SyntaxExtension>>, + pub exts: Option<Arc<SyntaxExtension>>, pub is_const: bool, } @@ -1017,7 +1018,7 @@ pub trait ResolverExpand { invoc: &Invocation, eager_expansion_root: LocalExpnId, force: bool, - ) -> Result<Lrc<SyntaxExtension>, Indeterminate>; + ) -> Result<Arc<SyntaxExtension>, Indeterminate>; fn record_macro_rule_usage(&mut self, mac_id: NodeId, rule_index: usize); diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index 8bf09cf96b3..ee7f68cc2f0 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -1,7 +1,8 @@ use rustc_ast::ptr::P; use rustc_ast::util::literal; use rustc_ast::{ - self as ast, AttrVec, BlockCheckMode, Expr, LocalKind, MatchKind, PatKind, UnOp, attr, token, + self as ast, AnonConst, AttrVec, BlockCheckMode, Expr, LocalKind, MatchKind, PatKind, UnOp, + attr, token, }; use rustc_span::source_map::Spanned; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; @@ -138,6 +139,42 @@ impl<'a> ExtCtxt<'a> { } } + pub fn lifetime_param( + &self, + span: Span, + ident: Ident, + bounds: ast::GenericBounds, + ) -> ast::GenericParam { + ast::GenericParam { + id: ast::DUMMY_NODE_ID, + ident: ident.with_span_pos(span), + attrs: AttrVec::new(), + bounds, + is_placeholder: false, + kind: ast::GenericParamKind::Lifetime, + colon_span: None, + } + } + + pub fn const_param( + &self, + span: Span, + ident: Ident, + bounds: ast::GenericBounds, + ty: P<ast::Ty>, + default: Option<AnonConst>, + ) -> ast::GenericParam { + ast::GenericParam { + id: ast::DUMMY_NODE_ID, + ident: ident.with_span_pos(span), + attrs: AttrVec::new(), + bounds, + is_placeholder: false, + kind: ast::GenericParamKind::Const { ty, kw_span: DUMMY_SP, default }, + colon_span: None, + } + } + pub fn trait_ref(&self, path: ast::Path) -> ast::TraitRef { ast::TraitRef { path, ref_id: ast::DUMMY_NODE_ID } } @@ -233,11 +270,14 @@ impl<'a> ExtCtxt<'a> { } pub fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> { - self.block(expr.span, thin_vec![ast::Stmt { - id: ast::DUMMY_NODE_ID, - span: expr.span, - kind: ast::StmtKind::Expr(expr), - }]) + self.block( + expr.span, + thin_vec![ast::Stmt { + id: ast::DUMMY_NODE_ID, + span: expr.span, + kind: ast::StmtKind::Expr(expr), + }], + ) } pub fn block(&self, span: Span, stmts: ThinVec<ast::Stmt>) -> P<ast::Block> { P(ast::Block { diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index ec497f6f8f1..e3f31ebeca3 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1,6 +1,7 @@ use std::ops::Deref; use std::path::PathBuf; use std::rc::Rc; +use std::sync::Arc; use std::{iter, mem}; use rustc_ast as ast; @@ -16,7 +17,6 @@ use rustc_ast::{ }; use rustc_ast_pretty::pprust; use rustc_data_structures::flat_map_in_place::FlatMapInPlace; -use rustc_data_structures::sync::Lrc; use rustc_errors::PResult; use rustc_feature::Features; use rustc_parse::parser::{ @@ -579,7 +579,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { &mut self, mut fragment: AstFragment, extra_placeholders: &[NodeId], - ) -> (AstFragment, Vec<(Invocation, Option<Lrc<SyntaxExtension>>)>) { + ) -> (AstFragment, Vec<(Invocation, Option<Arc<SyntaxExtension>>)>) { // Resolve `$crate`s in the fragment for pretty-printing. self.cx.resolver.resolve_dollar_crates(); @@ -1774,7 +1774,7 @@ fn build_single_delegations<'a, Node: InvocationCollectorNode>( struct InvocationCollector<'a, 'b> { cx: &'a mut ExtCtxt<'b>, - invocations: Vec<(Invocation, Option<Lrc<SyntaxExtension>>)>, + invocations: Vec<(Invocation, Option<Arc<SyntaxExtension>>)>, monotonic: bool, } diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 7ac9f453bae..b02a9b93c8a 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -405,26 +405,35 @@ pub fn compile_declarative_macro( // ...quasiquoting this would be nice. // These spans won't matter, anyways let argument_gram = vec![ - mbe::TokenTree::Sequence(DelimSpan::dummy(), mbe::SequenceRepetition { - tts: vec![ - mbe::TokenTree::MetaVarDecl(span, lhs_nm, tt_spec), - mbe::TokenTree::token(token::FatArrow, span), - mbe::TokenTree::MetaVarDecl(span, rhs_nm, tt_spec), - ], - separator: Some(Token::new(if macro_rules { token::Semi } else { token::Comma }, span)), - kleene: mbe::KleeneToken::new(mbe::KleeneOp::OneOrMore, span), - num_captures: 2, - }), + mbe::TokenTree::Sequence( + DelimSpan::dummy(), + mbe::SequenceRepetition { + tts: vec![ + mbe::TokenTree::MetaVarDecl(span, lhs_nm, tt_spec), + mbe::TokenTree::token(token::FatArrow, span), + mbe::TokenTree::MetaVarDecl(span, rhs_nm, tt_spec), + ], + separator: Some(Token::new( + if macro_rules { token::Semi } else { token::Comma }, + span, + )), + kleene: mbe::KleeneToken::new(mbe::KleeneOp::OneOrMore, span), + num_captures: 2, + }, + ), // to phase into semicolon-termination instead of semicolon-separation - mbe::TokenTree::Sequence(DelimSpan::dummy(), mbe::SequenceRepetition { - tts: vec![mbe::TokenTree::token( - if macro_rules { token::Semi } else { token::Comma }, - span, - )], - separator: None, - kleene: mbe::KleeneToken::new(mbe::KleeneOp::ZeroOrMore, span), - num_captures: 0, - }), + mbe::TokenTree::Sequence( + DelimSpan::dummy(), + mbe::SequenceRepetition { + tts: vec![mbe::TokenTree::token( + if macro_rules { token::Semi } else { token::Comma }, + span, + )], + separator: None, + kleene: mbe::KleeneToken::new(mbe::KleeneOp::ZeroOrMore, span), + num_captures: 0, + }, + ), ]; // Convert it into `MatcherLoc` form. let argument_gram = mbe::macro_parser::compute_locs(&argument_gram); diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs index a27d47892e4..b9a06157907 100644 --- a/compiler/rustc_expand/src/mbe/quoted.rs +++ b/compiler/rustc_expand/src/mbe/quoted.rs @@ -179,10 +179,10 @@ fn parse_tree<'a>( Some(&tokenstream::TokenTree::Delimited(delim_span, _, delim, ref tts)) => { if parsing_patterns { if delim != Delimiter::Parenthesis { - span_dollar_dollar_or_metavar_in_the_lhs_err(sess, &Token { - kind: token::OpenDelim(delim), - span: delim_span.entire(), - }); + span_dollar_dollar_or_metavar_in_the_lhs_err( + sess, + &Token { kind: token::OpenDelim(delim), span: delim_span.entire() }, + ); } } else { match delim { @@ -235,12 +235,10 @@ fn parse_tree<'a>( // Count the number of captured "names" (i.e., named metavars) let num_captures = if parsing_patterns { count_metavar_decls(&sequence) } else { 0 }; - TokenTree::Sequence(delim_span, SequenceRepetition { - tts: sequence, - separator, - kleene, - num_captures, - }) + TokenTree::Sequence( + delim_span, + SequenceRepetition { tts: sequence, separator, kleene, num_captures }, + ) } // `tree` is followed by an `ident`. This could be `$meta_var` or the `$crate` @@ -261,10 +259,10 @@ fn parse_tree<'a>( _, )) => { if parsing_patterns { - span_dollar_dollar_or_metavar_in_the_lhs_err(sess, &Token { - kind: token::Dollar, - span: dollar_span2, - }); + span_dollar_dollar_or_metavar_in_the_lhs_err( + sess, + &Token { kind: token::Dollar, span: dollar_span2 }, + ); } else { maybe_emit_macro_metavar_expr_feature(features, sess, dollar_span2); } @@ -289,12 +287,14 @@ fn parse_tree<'a>( // `tree` is the beginning of a delimited set of tokens (e.g., `(` or `{`). We need to // descend into the delimited set and further parse it. - &tokenstream::TokenTree::Delimited(span, spacing, delim, ref tts) => { - TokenTree::Delimited(span, spacing, Delimited { + &tokenstream::TokenTree::Delimited(span, spacing, delim, ref tts) => TokenTree::Delimited( + span, + spacing, + Delimited { delim, tts: parse(tts, parsing_patterns, sess, node_id, features, edition), - }) - } + }, + ), } } diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index 21688521ade..595c8c3279f 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -1,11 +1,11 @@ use std::mem; +use std::sync::Arc; use rustc_ast::ExprKind; use rustc_ast::mut_visit::{self, MutVisitor}; use rustc_ast::token::{self, Delimiter, IdentIsRaw, Lit, LitKind, Nonterminal, Token, TokenKind}; use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree}; use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::sync::Lrc; use rustc_errors::{Diag, DiagCtxtHandle, PResult, pluralize}; use rustc_parse::lexer::nfc_normalize; use rustc_parse::parser::ParseNtResult; @@ -299,7 +299,7 @@ pub(super) fn transcribe<'a>( marker.visit_span(&mut sp); let use_span = nt.use_span(); with_metavar_spans(|mspans| mspans.insert(use_span, sp)); - TokenTree::token_alone(token::Interpolated(Lrc::clone(nt)), sp) + TokenTree::token_alone(token::Interpolated(Arc::clone(nt)), sp) } MatchedSeq(..) => { // We were unable to descend far enough. This is an error. diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index 7eb09a64e96..5581a6e6508 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -1,4 +1,5 @@ use std::ops::{Bound, Range}; +use std::sync::Arc; use ast::token::IdentIsRaw; use pm::bridge::{ @@ -11,7 +12,6 @@ use rustc_ast::tokenstream::{self, DelimSpacing, Spacing, TokenStream}; use rustc_ast::util::literal::escape_byte_str_symbol; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::sync::Lrc; use rustc_errors::{Diag, ErrorGuaranteed, MultiSpan, PResult}; use rustc_parse::lexer::nfc_normalize; use rustc_parse::parser::Parser; @@ -446,7 +446,7 @@ impl<'a, 'b> Rustc<'a, 'b> { impl server::Types for Rustc<'_, '_> { type FreeFunctions = FreeFunctions; type TokenStream = TokenStream; - type SourceFile = Lrc<SourceFile>; + type SourceFile = Arc<SourceFile>; type Span = Span; type Symbol = Symbol; } @@ -657,7 +657,7 @@ impl server::TokenStream for Rustc<'_, '_> { impl server::SourceFile for Rustc<'_, '_> { fn eq(&mut self, file1: &Self::SourceFile, file2: &Self::SourceFile) -> bool { - Lrc::ptr_eq(file1, file2) + Arc::ptr_eq(file1, file2) } fn path(&mut self, file: &Self::SourceFile) -> String { | 
