Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce RPC overhead for common proc_macro operations #86822

Closed
wants to merge 11 commits into from
Closed
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3886,6 +3886,7 @@ dependencies = [
"rustc_span",
"smallvec",
"tracing",
"unicode-normalization",
]

[[package]]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_expand/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ rustc_parse = { path = "../rustc_parse" }
rustc_session = { path = "../rustc_session" }
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
rustc_ast = { path = "../rustc_ast" }
unicode-normalization = "0.1.11"
821 changes: 353 additions & 468 deletions compiler/rustc_expand/src/proc_macro_server.rs

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions library/proc_macro/src/bridge/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
//! Buffer management for same-process client<->server communication.

use std::io::{self, Write};
use std::marker::PhantomData;
use std::mem;
use std::ops::{Deref, DerefMut};
use std::slice;

#[repr(C)]
pub struct Slice<'a> {
data: *const u8,
len: usize,
_marker: PhantomData<&'a [u8]>,
}

unsafe impl<'a> Send for Slice<'a> {}
unsafe impl<'a> Sync for Slice<'a> {}

impl<'a> Copy for Slice<'a> {}
impl<'a> Clone for Slice<'a> {
fn clone(&self) -> Self {
*self
}
}

impl<'a> From<&'a [u8]> for Slice<'a> {
fn from(xs: &'a [u8]) -> Self {
Slice { data: xs.as_ptr(), len: xs.len(), _marker: PhantomData }
}
}

impl<'a> Deref for Slice<'a> {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe { slice::from_raw_parts(self.data, self.len) }
}
}

#[repr(C)]
pub struct Buffer {
data: *mut u8,
Expand Down
Loading