Skip to content

Commit b251053

Browse files
committed
proc_macro/bridge: remove client->server &HandleCounters passing.
1 parent ff86b27 commit b251053

File tree

2 files changed

+18
-33
lines changed

2 files changed

+18
-33
lines changed

library/proc_macro/src/bridge/client.rs

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,6 @@ macro_rules! define_handles {
99
'owned: $($oty:ident,)*
1010
'interned: $($ity:ident,)*
1111
) => {
12-
#[repr(C)]
13-
#[allow(non_snake_case)]
14-
pub struct HandleCounters {
15-
$($oty: AtomicUsize,)*
16-
$($ity: AtomicUsize,)*
17-
}
18-
19-
impl HandleCounters {
20-
// FIXME(eddyb) use a reference to the `static COUNTERS`, instead of
21-
// a wrapper `fn` pointer, once `const fn` can reference `static`s.
22-
extern "C" fn get() -> &'static Self {
23-
static COUNTERS: HandleCounters = HandleCounters {
24-
$($oty: AtomicUsize::new(1),)*
25-
$($ity: AtomicUsize::new(1),)*
26-
};
27-
&COUNTERS
28-
}
29-
}
3012

3113
// FIXME(eddyb) generate the definition of `HandleStore` in `server.rs`.
3214
#[repr(C)]
@@ -37,10 +19,22 @@ macro_rules! define_handles {
3719
}
3820

3921
impl<S: server::Types> HandleStore<S> {
40-
pub(super) fn new(handle_counters: &'static HandleCounters) -> Self {
22+
pub(super) fn new() -> Self {
23+
// FIXME(eddyb) these counters are server-side, so they don't
24+
// protect against the same proc macro dylib being used with
25+
// multiple servers - however, that's very unlikely, and should
26+
// be protected against through other means (e.g. forcing a
27+
// specific proc macro dylib to always talk to the same server
28+
// that initially loaded it).
4129
HandleStore {
42-
$($oty: handle::OwnedStore::new(&handle_counters.$oty),)*
43-
$($ity: handle::InternedStore::new(&handle_counters.$ity),)*
30+
$($oty: handle::OwnedStore::new({
31+
static COUNTER: AtomicUsize = AtomicUsize::new(1);
32+
&COUNTER
33+
}),)*
34+
$($ity: handle::InternedStore::new({
35+
static COUNTER: AtomicUsize = AtomicUsize::new(1);
36+
&COUNTER
37+
}),)*
4438
}
4539
}
4640
}
@@ -370,10 +364,6 @@ impl Bridge<'_> {
370364
/// and forcing the use of APIs that take/return `S::TokenStream`, server-side.
371365
#[repr(C)]
372366
pub struct Client<I, O> {
373-
// FIXME(eddyb) use a reference to the `static COUNTERS`, instead of
374-
// a wrapper `fn` pointer, once `const fn` can reference `static`s.
375-
pub(super) get_handle_counters: extern "C" fn() -> &'static HandleCounters,
376-
377367
pub(super) run: extern "C" fn(Bridge<'_>) -> Buffer,
378368

379369
pub(super) _marker: PhantomData<fn(I) -> O>,
@@ -433,7 +423,6 @@ fn run_client<A: for<'a, 's> DecodeMut<'a, 's, ()>, R: Encode<()>>(
433423
impl Client<crate::TokenStream, crate::TokenStream> {
434424
pub const fn expand1(f: impl Fn(crate::TokenStream) -> crate::TokenStream + Copy) -> Self {
435425
Client {
436-
get_handle_counters: HandleCounters::get,
437426
run: super::selfless_reify::reify_to_extern_c_fn_hrt_bridge(move |bridge| {
438427
run_client(bridge, |input| f(crate::TokenStream(input)).0)
439428
}),
@@ -447,7 +436,6 @@ impl Client<(crate::TokenStream, crate::TokenStream), crate::TokenStream> {
447436
f: impl Fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream + Copy,
448437
) -> Self {
449438
Client {
450-
get_handle_counters: HandleCounters::get,
451439
run: super::selfless_reify::reify_to_extern_c_fn_hrt_bridge(move |bridge| {
452440
run_client(bridge, |(input, input2)| {
453441
f(crate::TokenStream(input), crate::TokenStream(input2)).0

library/proc_macro/src/bridge/server.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,13 @@ fn run_server<
257257
O: for<'a, 's> DecodeMut<'a, 's, HandleStore<MarkedTypes<S>>>,
258258
>(
259259
strategy: &impl ExecutionStrategy,
260-
handle_counters: &'static client::HandleCounters,
261260
server: S,
262261
input: I,
263262
run_client: extern "C" fn(Bridge<'_>) -> Buffer,
264263
force_show_panics: bool,
265264
) -> Result<O, PanicMessage> {
266265
let mut dispatcher =
267-
Dispatcher { handle_store: HandleStore::new(handle_counters), server: MarkedTypes(server) };
266+
Dispatcher { handle_store: HandleStore::new(), server: MarkedTypes(server) };
268267

269268
let mut buf = Buffer::new();
270269
input.encode(&mut buf, &mut dispatcher.handle_store);
@@ -282,10 +281,9 @@ impl client::Client<crate::TokenStream, crate::TokenStream> {
282281
input: S::TokenStream,
283282
force_show_panics: bool,
284283
) -> Result<S::TokenStream, PanicMessage> {
285-
let client::Client { get_handle_counters, run, _marker } = *self;
284+
let client::Client { run, _marker } = *self;
286285
run_server(
287286
strategy,
288-
get_handle_counters(),
289287
server,
290288
<MarkedTypes<S> as Types>::TokenStream::mark(input),
291289
run,
@@ -304,10 +302,9 @@ impl client::Client<(crate::TokenStream, crate::TokenStream), crate::TokenStream
304302
input2: S::TokenStream,
305303
force_show_panics: bool,
306304
) -> Result<S::TokenStream, PanicMessage> {
307-
let client::Client { get_handle_counters, run, _marker } = *self;
305+
let client::Client { run, _marker } = *self;
308306
run_server(
309307
strategy,
310-
get_handle_counters(),
311308
server,
312309
(
313310
<MarkedTypes<S> as Types>::TokenStream::mark(input),

0 commit comments

Comments
 (0)