diff --git a/library/proc_macro/src/bridge/client.rs b/library/proc_macro/src/bridge/client.rs index c38457ac6712d..e373ce6e6e650 100644 --- a/library/proc_macro/src/bridge/client.rs +++ b/library/proc_macro/src/bridge/client.rs @@ -9,24 +9,6 @@ macro_rules! define_handles { 'owned: $($oty:ident,)* 'interned: $($ity:ident,)* ) => { - #[repr(C)] - #[allow(non_snake_case)] - pub struct HandleCounters { - $($oty: AtomicUsize,)* - $($ity: AtomicUsize,)* - } - - impl HandleCounters { - // FIXME(eddyb) use a reference to the `static COUNTERS`, instead of - // a wrapper `fn` pointer, once `const fn` can reference `static`s. - extern "C" fn get() -> &'static Self { - static COUNTERS: HandleCounters = HandleCounters { - $($oty: AtomicUsize::new(1),)* - $($ity: AtomicUsize::new(1),)* - }; - &COUNTERS - } - } // FIXME(eddyb) generate the definition of `HandleStore` in `server.rs`. #[repr(C)] @@ -37,10 +19,22 @@ macro_rules! define_handles { } impl HandleStore { - pub(super) fn new(handle_counters: &'static HandleCounters) -> Self { + pub(super) fn new() -> Self { + // FIXME(eddyb) these counters are server-side, so they don't + // protect against the same proc macro dylib being used with + // multiple servers - however, that's very unlikely, and should + // be protected against through other means (e.g. forcing a + // specific proc macro dylib to always talk to the same server + // that initially loaded it). HandleStore { - $($oty: handle::OwnedStore::new(&handle_counters.$oty),)* - $($ity: handle::InternedStore::new(&handle_counters.$ity),)* + $($oty: handle::OwnedStore::new({ + static COUNTER: AtomicUsize = AtomicUsize::new(1); + &COUNTER + }),)* + $($ity: handle::InternedStore::new({ + static COUNTER: AtomicUsize = AtomicUsize::new(1); + &COUNTER + }),)* } } } @@ -370,10 +364,6 @@ impl Bridge<'_> { /// and forcing the use of APIs that take/return `S::TokenStream`, server-side. #[repr(C)] pub struct Client { - // FIXME(eddyb) use a reference to the `static COUNTERS`, instead of - // a wrapper `fn` pointer, once `const fn` can reference `static`s. - pub(super) get_handle_counters: extern "C" fn() -> &'static HandleCounters, - pub(super) run: extern "C" fn(Bridge<'_>) -> Buffer, pub(super) _marker: PhantomData O>, @@ -433,7 +423,6 @@ fn run_client DecodeMut<'a, 's, ()>, R: Encode<()>>( impl Client { pub const fn expand1(f: impl Fn(crate::TokenStream) -> crate::TokenStream + Copy) -> Self { Client { - get_handle_counters: HandleCounters::get, run: super::selfless_reify::reify_to_extern_c_fn_hrt_bridge(move |bridge| { run_client(bridge, |input| f(crate::TokenStream(input)).0) }), @@ -447,7 +436,6 @@ impl Client<(crate::TokenStream, crate::TokenStream), crate::TokenStream> { f: impl Fn(crate::TokenStream, crate::TokenStream) -> crate::TokenStream + Copy, ) -> Self { Client { - get_handle_counters: HandleCounters::get, run: super::selfless_reify::reify_to_extern_c_fn_hrt_bridge(move |bridge| { run_client(bridge, |(input, input2)| { f(crate::TokenStream(input), crate::TokenStream(input2)).0 diff --git a/library/proc_macro/src/bridge/server.rs b/library/proc_macro/src/bridge/server.rs index cbddf39da44d2..408f19e362a9a 100644 --- a/library/proc_macro/src/bridge/server.rs +++ b/library/proc_macro/src/bridge/server.rs @@ -257,14 +257,13 @@ fn run_server< O: for<'a, 's> DecodeMut<'a, 's, HandleStore>>, >( strategy: &impl ExecutionStrategy, - handle_counters: &'static client::HandleCounters, server: S, input: I, run_client: extern "C" fn(Bridge<'_>) -> Buffer, force_show_panics: bool, ) -> Result { let mut dispatcher = - Dispatcher { handle_store: HandleStore::new(handle_counters), server: MarkedTypes(server) }; + Dispatcher { handle_store: HandleStore::new(), server: MarkedTypes(server) }; let mut buf = Buffer::new(); input.encode(&mut buf, &mut dispatcher.handle_store); @@ -282,10 +281,9 @@ impl client::Client { input: S::TokenStream, force_show_panics: bool, ) -> Result { - let client::Client { get_handle_counters, run, _marker } = *self; + let client::Client { run, _marker } = *self; run_server( strategy, - get_handle_counters(), server, as Types>::TokenStream::mark(input), run, @@ -304,10 +302,9 @@ impl client::Client<(crate::TokenStream, crate::TokenStream), crate::TokenStream input2: S::TokenStream, force_show_panics: bool, ) -> Result { - let client::Client { get_handle_counters, run, _marker } = *self; + let client::Client { run, _marker } = *self; run_server( strategy, - get_handle_counters(), server, ( as Types>::TokenStream::mark(input),