Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,11 @@ impl<'a, 'b> Rustc<'a, 'b> {
}
}

impl server::Types for Rustc<'_, '_> {
impl server::Server for Rustc<'_, '_> {
type TokenStream = TokenStream;
type Span = Span;
type Symbol = Symbol;
}

impl server::Server for Rustc<'_, '_> {
fn globals(&mut self) -> ExpnGlobals<Self::Span> {
ExpnGlobals {
def_site: self.def_site,
Expand Down
25 changes: 8 additions & 17 deletions library/proc_macro/src/bridge/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ impl Drop for TokenStream {
}

impl<S> Encode<S> for TokenStream {
fn encode(self, w: &mut Writer, s: &mut S) {
fn encode(self, w: &mut Buffer, s: &mut S) {
mem::ManuallyDrop::new(self).handle.encode(w, s);
}
}

impl<S> Encode<S> for &TokenStream {
fn encode(self, w: &mut Writer, s: &mut S) {
fn encode(self, w: &mut Buffer, s: &mut S) {
self.handle.encode(w, s);
}
}

impl<S> Decode<'_, '_, S> for TokenStream {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
fn decode(r: &mut &[u8], s: &mut S) -> Self {
TokenStream { handle: handle::Handle::decode(r, s) }
}
}
Expand All @@ -56,23 +56,17 @@ impl !Send for Span {}
impl !Sync for Span {}

impl<S> Encode<S> for Span {
fn encode(self, w: &mut Writer, s: &mut S) {
fn encode(self, w: &mut Buffer, s: &mut S) {
self.handle.encode(w, s);
}
}

impl<S> Decode<'_, '_, S> for Span {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
fn decode(r: &mut &[u8], s: &mut S) -> Self {
Span { handle: handle::Handle::decode(r, s) }
}
}

// FIXME(eddyb) generate these impls by pattern-matching on the
// names of methods - also could use the presence of `fn drop`
// to distinguish between 'owned and 'interned, above.
// Alternatively, special "modes" could be listed of types in with_api
// instead of pattern matching on methods, here and in server decl.

impl Clone for TokenStream {
fn clone(&self) -> Self {
Methods::ts_clone(self)
Expand Down Expand Up @@ -104,18 +98,15 @@ pub(crate) use super::symbol::Symbol;

macro_rules! define_client_side {
(
Methods {
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)*;)*
},
$($name:ident),* $(,)?
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)*;)*
) => {
impl Methods {
$(pub(crate) fn $method($($arg: $arg_ty),*) $(-> $ret_ty)? {
Bridge::with(|bridge| {
let mut buf = bridge.cached_buffer.take();

buf.clear();
api_tags::Method::$method.encode(&mut buf, &mut ());
ApiTags::$method.encode(&mut buf, &mut ());
$($arg.encode(&mut buf, &mut ());)*

buf = bridge.dispatch.call(buf);
Expand All @@ -130,7 +121,7 @@ macro_rules! define_client_side {
}
}
}
with_api!(self, self, define_client_side);
with_api!(self, define_client_side);

struct Bridge<'a> {
/// Reusable buffer (only `clear`-ed, never shrunk), primarily
Expand Down
Loading
Loading