proc_macro: stop using a remote object handle for Group

This greatly reduces round-trips to fetch relevant extra information about the
token in proc macro code, and avoids RPC messages to create Group tokens.
This commit is contained in:
Nika Layzell
2021-07-01 17:36:38 -04:00
parent 72bfe618fa
commit f28dfdf1c7
5 changed files with 204 additions and 249 deletions

View File

@@ -212,8 +212,8 @@ pub use quote::{quote, quote_span};
fn tree_to_bridge_tree(
tree: TokenTree,
) -> bridge::TokenTree<
bridge::client::TokenStream,
bridge::client::Span,
bridge::client::Group,
bridge::client::Ident,
bridge::client::Literal,
> {
@@ -238,8 +238,8 @@ impl From<TokenTree> for TokenStream {
struct ConcatTreesHelper {
trees: Vec<
bridge::TokenTree<
bridge::client::TokenStream,
bridge::client::Span,
bridge::client::Group,
bridge::client::Ident,
bridge::client::Literal,
>,
@@ -365,8 +365,8 @@ pub mod token_stream {
pub struct IntoIter(
std::vec::IntoIter<
bridge::TokenTree<
bridge::client::TokenStream,
bridge::client::Span,
bridge::client::Group,
bridge::client::Ident,
bridge::client::Literal,
>,
@@ -788,7 +788,7 @@ impl fmt::Display for TokenTree {
/// A `Group` internally contains a `TokenStream` which is surrounded by `Delimiter`s.
#[derive(Clone)]
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub struct Group(bridge::client::Group);
pub struct Group(bridge::Group<bridge::client::TokenStream, bridge::client::Span>);
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
impl !Send for Group {}
@@ -825,13 +825,17 @@ impl Group {
/// method below.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn new(delimiter: Delimiter, stream: TokenStream) -> Group {
Group(bridge::client::Group::new(delimiter, stream.0))
Group(bridge::Group {
delimiter,
stream: stream.0,
span: bridge::DelimSpan::from_single(Span::call_site().0),
})
}
/// Returns the delimiter of this `Group`
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn delimiter(&self) -> Delimiter {
self.0.delimiter()
self.0.delimiter
}
/// Returns the `TokenStream` of tokens that are delimited in this `Group`.
@@ -840,7 +844,7 @@ impl Group {
/// returned above.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn stream(&self) -> TokenStream {
TokenStream(Some(self.0.stream()))
TokenStream(self.0.stream.clone())
}
/// Returns the span for the delimiters of this token stream, spanning the
@@ -852,7 +856,7 @@ impl Group {
/// ```
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn span(&self) -> Span {
Span(self.0.span())
Span(self.0.span.entire)
}
/// Returns the span pointing to the opening delimiter of this group.
@@ -863,7 +867,7 @@ impl Group {
/// ```
#[stable(feature = "proc_macro_group_span", since = "1.55.0")]
pub fn span_open(&self) -> Span {
Span(self.0.span_open())
Span(self.0.span.open)
}
/// Returns the span pointing to the closing delimiter of this group.
@@ -874,7 +878,7 @@ impl Group {
/// ```
#[stable(feature = "proc_macro_group_span", since = "1.55.0")]
pub fn span_close(&self) -> Span {
Span(self.0.span_close())
Span(self.0.span.close)
}
/// Configures the span for this `Group`'s delimiters, but not its internal
@@ -885,7 +889,7 @@ impl Group {
/// tokens at the level of the `Group`.
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
pub fn set_span(&mut self, span: Span) {
self.0.set_span(span.0);
self.0.span = bridge::DelimSpan::from_single(span.0);
}
}