Skip to content

Commit 84bb764

Browse files
Rollup merge of #151694 - cyrgani:more-pm-cleanup, r=petrochenkov
more `proc_macro` bridge cleanups Some followups made possible by #151505.
2 parents 80102f3 + 6e7a87c commit 84bb764

File tree

9 files changed

+166
-278
lines changed

9 files changed

+166
-278
lines changed

compiler/rustc_expand/src/proc_macro_server.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,11 @@ impl<'a, 'b> Rustc<'a, 'b> {
458458
}
459459
}
460460

461-
impl server::Types for Rustc<'_, '_> {
461+
impl server::Server for Rustc<'_, '_> {
462462
type TokenStream = TokenStream;
463463
type Span = Span;
464464
type Symbol = Symbol;
465-
}
466465

467-
impl server::Server for Rustc<'_, '_> {
468466
fn globals(&mut self) -> ExpnGlobals<Self::Span> {
469467
ExpnGlobals {
470468
def_site: self.def_site,

library/proc_macro/src/bridge/client.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ impl Drop for TokenStream {
3030
}
3131

3232
impl<S> Encode<S> for TokenStream {
33-
fn encode(self, w: &mut Writer, s: &mut S) {
33+
fn encode(self, w: &mut Buffer, s: &mut S) {
3434
mem::ManuallyDrop::new(self).handle.encode(w, s);
3535
}
3636
}
3737

3838
impl<S> Encode<S> for &TokenStream {
39-
fn encode(self, w: &mut Writer, s: &mut S) {
39+
fn encode(self, w: &mut Buffer, s: &mut S) {
4040
self.handle.encode(w, s);
4141
}
4242
}
4343

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

5858
impl<S> Encode<S> for Span {
59-
fn encode(self, w: &mut Writer, s: &mut S) {
59+
fn encode(self, w: &mut Buffer, s: &mut S) {
6060
self.handle.encode(w, s);
6161
}
6262
}
6363

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

70-
// FIXME(eddyb) generate these impls by pattern-matching on the
71-
// names of methods - also could use the presence of `fn drop`
72-
// to distinguish between 'owned and 'interned, above.
73-
// Alternatively, special "modes" could be listed of types in with_api
74-
// instead of pattern matching on methods, here and in server decl.
75-
7670
impl Clone for TokenStream {
7771
fn clone(&self) -> Self {
7872
Methods::ts_clone(self)
@@ -104,18 +98,15 @@ pub(crate) use super::symbol::Symbol;
10498

10599
macro_rules! define_client_side {
106100
(
107-
Methods {
108-
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)*;)*
109-
},
110-
$($name:ident),* $(,)?
101+
$(fn $method:ident($($arg:ident: $arg_ty:ty),* $(,)?) $(-> $ret_ty:ty)*;)*
111102
) => {
112103
impl Methods {
113104
$(pub(crate) fn $method($($arg: $arg_ty),*) $(-> $ret_ty)? {
114105
Bridge::with(|bridge| {
115106
let mut buf = bridge.cached_buffer.take();
116107

117108
buf.clear();
118-
api_tags::Method::$method.encode(&mut buf, &mut ());
109+
ApiTags::$method.encode(&mut buf, &mut ());
119110
$($arg.encode(&mut buf, &mut ());)*
120111

121112
buf = bridge.dispatch.call(buf);
@@ -130,7 +121,7 @@ macro_rules! define_client_side {
130121
}
131122
}
132123
}
133-
with_api!(self, self, define_client_side);
124+
with_api!(self, define_client_side);
134125

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

0 commit comments

Comments
 (0)