Skip to content

Commit

Permalink
Remove TODO in proc_macro now const_refs_to_static is stable
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Oct 17, 2024
1 parent 6c85d31 commit 019ad0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
23 changes: 7 additions & 16 deletions proc_macro/src/bridge/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,10 @@ macro_rules! define_client_handles {
$(pub(super) $ity: AtomicU32,)*
}

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: AtomicU32::new(1),)*
$($ity: AtomicU32::new(1),)*
};
&COUNTERS
}
}
static COUNTERS: HandleCounters = HandleCounters {
$($oty: AtomicU32::new(1),)*
$($ity: AtomicU32::new(1),)*
};

$(
pub(crate) struct $oty {
Expand Down Expand Up @@ -259,9 +252,7 @@ pub(crate) fn is_available() -> bool {
/// and forcing the use of APIs that take/return `S::TokenStream`, server-side.
#[repr(C)]
pub struct Client<I, O> {
// 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) handle_counters: &'static HandleCounters,

pub(super) run: extern "C" fn(BridgeConfig<'_>) -> Buffer,

Expand Down Expand Up @@ -346,7 +337,7 @@ fn run_client<A: for<'a, 's> DecodeMut<'a, 's, ()>, R: Encode<()>>(
impl Client<crate::TokenStream, crate::TokenStream> {
pub const fn expand1(f: impl Fn(crate::TokenStream) -> crate::TokenStream + Copy) -> Self {
Client {
get_handle_counters: HandleCounters::get,
handle_counters: &COUNTERS,
run: super::selfless_reify::reify_to_extern_c_fn_hrt_bridge(move |bridge| {
run_client(bridge, |input| f(crate::TokenStream(Some(input))).0)
}),
Expand All @@ -360,7 +351,7 @@ 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,
handle_counters: &COUNTERS,
run: super::selfless_reify::reify_to_extern_c_fn_hrt_bridge(move |bridge| {
run_client(bridge, |(input, input2)| {
f(crate::TokenStream(Some(input)), crate::TokenStream(Some(input2))).0
Expand Down
8 changes: 4 additions & 4 deletions proc_macro/src/bridge/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@ impl client::Client<crate::TokenStream, crate::TokenStream> {
S: Server,
S::TokenStream: Default,
{
let client::Client { get_handle_counters, run, _marker } = *self;
let client::Client { handle_counters, run, _marker } = *self;
run_server(
strategy,
get_handle_counters(),
handle_counters,
server,
<MarkedTypes<S> as Types>::TokenStream::mark(input),
run,
Expand All @@ -426,10 +426,10 @@ impl client::Client<(crate::TokenStream, crate::TokenStream), crate::TokenStream
S: Server,
S::TokenStream: Default,
{
let client::Client { get_handle_counters, run, _marker } = *self;
let client::Client { handle_counters, run, _marker } = *self;
run_server(
strategy,
get_handle_counters(),
handle_counters,
server,
(
<MarkedTypes<S> as Types>::TokenStream::mark(input),
Expand Down

0 comments on commit 019ad0c

Please sign in to comment.