Skip to content

Commit cc347df

Browse files
committed
proc_macro: Rename ExpnContext to ExpnGlobals, and unify method on Server trait
1 parent 9ff505c commit cc347df

File tree

3 files changed

+18
-30
lines changed

3 files changed

+18
-30
lines changed

proc_macro/src/bridge/client.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,15 @@ impl Clone for SourceFile {
232232

233233
impl Span {
234234
pub(crate) fn def_site() -> Span {
235-
Bridge::with(|bridge| bridge.context.def_site)
235+
Bridge::with(|bridge| bridge.globals.def_site)
236236
}
237237

238238
pub(crate) fn call_site() -> Span {
239-
Bridge::with(|bridge| bridge.context.call_site)
239+
Bridge::with(|bridge| bridge.globals.call_site)
240240
}
241241

242242
pub(crate) fn mixed_site() -> Span {
243-
Bridge::with(|bridge| bridge.context.mixed_site)
243+
Bridge::with(|bridge| bridge.globals.mixed_site)
244244
}
245245
}
246246

@@ -285,8 +285,8 @@ struct Bridge<'a> {
285285
/// Server-side function that the client uses to make requests.
286286
dispatch: closure::Closure<'a, Buffer, Buffer>,
287287

288-
/// Provided context for this macro expansion.
289-
context: ExpnContext<Span>,
288+
/// Provided globals for this macro expansion.
289+
globals: ExpnGlobals<Span>,
290290
}
291291

292292
impl<'a> !Send for Bridge<'a> {}
@@ -414,11 +414,11 @@ fn run_client<A: for<'a, 's> DecodeMut<'a, 's, ()>, R: Encode<()>>(
414414
maybe_install_panic_hook(force_show_panics);
415415

416416
let reader = &mut &buf[..];
417-
let (input, context) = <(A, ExpnContext<Span>)>::decode(reader, &mut ());
417+
let (globals, input) = <(ExpnGlobals<Span>, A)>::decode(reader, &mut ());
418418

419419
// Put the buffer we used for input back in the `Bridge` for requests.
420420
let new_state =
421-
BridgeState::Connected(Bridge { cached_buffer: buf.take(), dispatch, context });
421+
BridgeState::Connected(Bridge { cached_buffer: buf.take(), dispatch, globals });
422422

423423
BRIDGE_STATE.with(|state| {
424424
state.set(new_state, || {

proc_macro/src/bridge/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -465,15 +465,15 @@ compound_traits!(
465465
}
466466
);
467467

468-
/// Context provided alongside the initial inputs for a macro expansion.
468+
/// Globals provided alongside the initial inputs for a macro expansion.
469469
/// Provides values such as spans which are used frequently to avoid RPC.
470470
#[derive(Clone)]
471-
struct ExpnContext<S> {
472-
def_site: S,
473-
call_site: S,
474-
mixed_site: S,
471+
pub struct ExpnGlobals<S> {
472+
pub def_site: S,
473+
pub call_site: S,
474+
pub mixed_site: S,
475475
}
476476

477477
compound_traits!(
478-
struct ExpnContext<Sp> { def_site, call_site, mixed_site }
478+
struct ExpnGlobals<Sp> { def_site, call_site, mixed_site }
479479
);

proc_macro/src/bridge/server.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ macro_rules! declare_server_traits {
3939
})*
4040

4141
pub trait Server: Types $(+ $name)* {
42-
fn def_site(&mut self) -> Self::Span;
43-
fn call_site(&mut self) -> Self::Span;
44-
fn mixed_site(&mut self) -> Self::Span;
42+
fn globals(&mut self) -> ExpnGlobals<Self::Span>;
4543
}
4644
}
4745
}
@@ -50,14 +48,8 @@ with_api!(Self, self_, declare_server_traits);
5048
pub(super) struct MarkedTypes<S: Types>(S);
5149

5250
impl<S: Server> Server for MarkedTypes<S> {
53-
fn def_site(&mut self) -> Self::Span {
54-
<_>::mark(Server::def_site(&mut self.0))
55-
}
56-
fn call_site(&mut self) -> Self::Span {
57-
<_>::mark(Server::call_site(&mut self.0))
58-
}
59-
fn mixed_site(&mut self) -> Self::Span {
60-
<_>::mark(Server::mixed_site(&mut self.0))
51+
fn globals(&mut self) -> ExpnGlobals<Self::Span> {
52+
<_>::mark(Server::globals(&mut self.0))
6153
}
6254
}
6355

@@ -279,14 +271,10 @@ fn run_server<
279271
let mut dispatcher =
280272
Dispatcher { handle_store: HandleStore::new(handle_counters), server: MarkedTypes(server) };
281273

282-
let expn_context = ExpnContext {
283-
def_site: dispatcher.server.def_site(),
284-
call_site: dispatcher.server.call_site(),
285-
mixed_site: dispatcher.server.mixed_site(),
286-
};
274+
let globals = dispatcher.server.globals();
287275

288276
let mut buf = Buffer::new();
289-
(input, expn_context).encode(&mut buf, &mut dispatcher.handle_store);
277+
(globals, input).encode(&mut buf, &mut dispatcher.handle_store);
290278

291279
buf = strategy.run_bridge_and_client(&mut dispatcher, buf, run_client, force_show_panics);
292280

0 commit comments

Comments
 (0)