Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions library/proc_macro/src/bridge/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@ macro_rules! define_client_handles {
$(
pub(crate) struct $oty {
handle: handle::Handle,
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual
// way of doing this, but that requires unstable features.
// rust-analyzer uses this code and avoids unstable features.
_marker: PhantomData<*mut ()>,
}

impl !Send for $oty {}
impl !Sync for $oty {}

// Forward `Drop::drop` to the inherent `drop` method.
impl Drop for $oty {
fn drop(&mut self) {
$oty {
handle: self.handle,
_marker: PhantomData,
}.drop();
}
}
Expand All @@ -64,7 +62,6 @@ macro_rules! define_client_handles {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
$oty {
handle: handle::Handle::decode(r, s),
_marker: PhantomData,
}
}
}
Expand All @@ -74,12 +71,11 @@ macro_rules! define_client_handles {
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub(crate) struct $ity {
handle: handle::Handle,
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual
// way of doing this, but that requires unstable features.
// rust-analyzer uses this code and avoids unstable features.
_marker: PhantomData<*mut ()>,
}

impl !Send for $ity {}
impl !Sync for $ity {}

impl<S> Encode<S> for $ity {
fn encode(self, w: &mut Writer, s: &mut S) {
self.handle.encode(w, s);
Expand All @@ -90,7 +86,6 @@ macro_rules! define_client_handles {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
$ity {
handle: handle::Handle::decode(r, s),
_marker: PhantomData,
}
}
}
Expand Down Expand Up @@ -144,7 +139,7 @@ macro_rules! define_client_side {

buf.clear();
api_tags::Method::$name(api_tags::$name::$method).encode(&mut buf, &mut ());
reverse_encode!(buf; $($arg),*);
$($arg.encode(&mut buf, &mut ());)*

buf = bridge.dispatch.call(buf);

Expand Down
4 changes: 1 addition & 3 deletions library/proc_macro/src/bridge/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use std::marker::PhantomData;
pub(super) struct Closure<'a, A, R> {
call: unsafe extern "C" fn(*mut Env, A) -> R,
env: *mut Env,
// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual way of doing
// this, but that requires unstable features. rust-analyzer uses this code
// and avoids unstable features.
// Prevent Send and Sync impls.
//
// The `'a` lifetime parameter represents the lifetime of `Env`.
_marker: PhantomData<*mut &'a mut ()>,
Expand Down
28 changes: 3 additions & 25 deletions library/proc_macro/src/bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,26 +119,6 @@ macro_rules! with_api_handle_types {
};
}

// FIXME(eddyb) this calls `encode` for each argument, but in reverse,
// to match the ordering in `reverse_decode`.
macro_rules! reverse_encode {
($writer:ident;) => {};
($writer:ident; $first:ident $(, $rest:ident)*) => {
reverse_encode!($writer; $($rest),*);
$first.encode(&mut $writer, &mut ());
}
}

// FIXME(eddyb) this calls `decode` for each argument, but in reverse,
// to avoid borrow conflicts from borrows started by `&mut` arguments.
macro_rules! reverse_decode {
($reader:ident, $s:ident;) => {};
($reader:ident, $s:ident; $first:ident: $first_ty:ty $(, $rest:ident: $rest_ty:ty)*) => {
reverse_decode!($reader, $s; $($rest: $rest_ty),*);
let $first = <$first_ty>::decode(&mut $reader, $s);
}
}

#[allow(unsafe_code)]
mod arena;
#[allow(unsafe_code)]
Expand Down Expand Up @@ -180,13 +160,11 @@ pub struct BridgeConfig<'a> {

/// If 'true', always invoke the default panic hook
force_show_panics: bool,

// Prevent Send and Sync impls. `!Send`/`!Sync` is the usual way of doing
// this, but that requires unstable features. rust-analyzer uses this code
// and avoids unstable features.
_marker: marker::PhantomData<*mut ()>,
}

impl !Send for BridgeConfig<'_> {}
impl !Sync for BridgeConfig<'_> {}

#[forbid(unsafe_code)]
#[allow(non_camel_case_types)]
mod api_tags {
Expand Down
16 changes: 3 additions & 13 deletions library/proc_macro/src/bridge/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ macro_rules! define_dispatcher_impl {
$(api_tags::Method::$name(m) => match m {
$(api_tags::$name::$method => {
let mut call_method = || {
reverse_decode!(reader, handle_store; $($arg: $arg_ty),*);
$(let $arg = <$arg_ty>::decode(&mut reader, handle_store);)*
$name::$method(server, $($arg),*)
};
// HACK(eddyb) don't use `panic::catch_unwind` in a panic.
Expand Down Expand Up @@ -295,12 +295,7 @@ impl ExecutionStrategy for SameThread {

let mut dispatch = |buf| dispatcher.dispatch(buf);

run_client(BridgeConfig {
input,
dispatch: (&mut dispatch).into(),
force_show_panics,
_marker: marker::PhantomData,
})
run_client(BridgeConfig { input, dispatch: (&mut dispatch).into(), force_show_panics })
}
}

Expand Down Expand Up @@ -331,12 +326,7 @@ where
client.recv().expect("server died while client waiting for reply")
};

run_client(BridgeConfig {
input,
dispatch: (&mut dispatch).into(),
force_show_panics,
_marker: marker::PhantomData,
})
run_client(BridgeConfig { input, dispatch: (&mut dispatch).into(), force_show_panics })
});

while let Some(b) = server.recv() {
Expand Down
1 change: 0 additions & 1 deletion library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#![feature(panic_can_unwind)]
#![feature(restricted_std)]
#![feature(rustc_attrs)]
#![feature(stmt_expr_attributes)]
#![feature(extend_one)]
#![recursion_limit = "256"]
#![allow(internal_features)]
Expand Down
Loading