Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
53469cf
fix typo in documentation for std::fs::Permissions
squell Mar 17, 2023
0df002a
rewording after comments by @thomcc
squell Aug 29, 2023
2ed49fc
Convert `Unix{Datagram,Stream}::{set_}passcred()` to per-OS traits
jmillikin Oct 25, 2023
71a6973
Update E0716.md for clarity
carschandler Feb 5, 2024
b353765
remove potentially misleading sentence about libc::access
squell Feb 22, 2024
c0ce0f3
Display short types for unimplemented trait
jieyouxu Feb 28, 2024
a1dbb61
Unify long type name file and note in note_obligation_cause_code
jieyouxu Feb 28, 2024
d89c2c5
Small clean up of E0277 message logic
estebank Feb 29, 2024
69f2c9c
Move `gather_comments`.
nnethercote Nov 27, 2023
392159b
Move `HandleStore` into `server.rs`.
nnethercote Mar 1, 2024
fb8ac06
remove hidden use of Global
shamatar Mar 1, 2024
bcccab8
Use the guaranteed precision of a couple of float functions in docs
tbu- Mar 1, 2024
62baa67
Avoid silently writing to a file when the involved ty is long
jieyouxu Mar 1, 2024
50ff362
Update E0716.md
carschandler Mar 1, 2024
7f97dfe
Account for unmet `T: !Copy` in E0277 message
estebank Feb 29, 2024
aeee1f5
Rollup merge of #109263 - squell:master, r=cuviper
Dylan-DPC Mar 2, 2024
0fc922c
Rollup merge of #117156 - jmillikin:os-unix-socket-ext, r=Amanieu,dto…
Dylan-DPC Mar 2, 2024
03a53eb
Rollup merge of #120684 - carschandler:patch-1, r=nnethercote
Dylan-DPC Mar 2, 2024
6f6cc27
Rollup merge of #121739 - jieyouxu:loooong-typename, r=estebank
Dylan-DPC Mar 2, 2024
0c46bc1
Rollup merge of #121815 - nnethercote:mv-gather_comments, r=est31
Dylan-DPC Mar 2, 2024
319228e
Rollup merge of #121835 - nnethercote:mv-HandleStore, r=bjorn3
Dylan-DPC Mar 2, 2024
9c40705
Rollup merge of #121847 - shamatar:btreemap_fix_implicits, r=cuviper
Dylan-DPC Mar 2, 2024
8e8d5af
Rollup merge of #121861 - tbu-:pr_floating_point_exact_examples, r=wo…
Dylan-DPC Mar 2, 2024
a404b52
Rollup merge of #121875 - estebank:e0277-drive-by, r=compiler-errors
Dylan-DPC Mar 2, 2024
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
Prev Previous commit
Next Next commit
Move HandleStore into server.rs.
This just moves the server-relevant parts of handles into `server.rs`.
It introduces a new higher-order macro `with_api_handle_types` to avoid
some duplication.

This fixes two `FIXME` comments, and makes things clearer, by not having
server code in `client.rs`.
  • Loading branch information
nnethercote committed Mar 1, 2024
commit 392159b5618192af5761788d2c7e8256b331ce95
85 changes: 5 additions & 80 deletions library/proc_macro/src/bridge/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ use super::*;
use std::marker::PhantomData;
use std::sync::atomic::AtomicU32;

macro_rules! define_handles {
macro_rules! define_client_handles {
(
'owned: $($oty:ident,)*
'interned: $($ity:ident,)*
) => {
#[repr(C)]
#[allow(non_snake_case)]
pub struct HandleCounters {
$($oty: AtomicU32,)*
$($ity: AtomicU32,)*
pub(super) struct HandleCounters {
$(pub(super) $oty: AtomicU32,)*
$(pub(super) $ity: AtomicU32,)*
}

impl HandleCounters {
Expand All @@ -29,22 +29,6 @@ macro_rules! define_handles {
}
}

// FIXME(eddyb) generate the definition of `HandleStore` in `server.rs`.
#[allow(non_snake_case)]
pub(super) struct HandleStore<S: server::Types> {
$($oty: handle::OwnedStore<S::$oty>,)*
$($ity: handle::InternedStore<S::$ity>,)*
}

impl<S: server::Types> HandleStore<S> {
pub(super) fn new(handle_counters: &'static HandleCounters) -> Self {
HandleStore {
$($oty: handle::OwnedStore::new(&handle_counters.$oty),)*
$($ity: handle::InternedStore::new(&handle_counters.$ity),)*
}
}
}

$(
pub(crate) struct $oty {
handle: handle::Handle,
Expand Down Expand Up @@ -72,53 +56,18 @@ macro_rules! define_handles {
}
}

impl<S: server::Types> DecodeMut<'_, '_, HandleStore<server::MarkedTypes<S>>>
for Marked<S::$oty, $oty>
{
fn decode(r: &mut Reader<'_>, s: &mut HandleStore<server::MarkedTypes<S>>) -> Self {
s.$oty.take(handle::Handle::decode(r, &mut ()))
}
}

impl<S> Encode<S> for &$oty {
fn encode(self, w: &mut Writer, s: &mut S) {
self.handle.encode(w, s);
}
}

impl<'s, S: server::Types> Decode<'_, 's, HandleStore<server::MarkedTypes<S>>>
for &'s Marked<S::$oty, $oty>
{
fn decode(r: &mut Reader<'_>, s: &'s HandleStore<server::MarkedTypes<S>>) -> Self {
&s.$oty[handle::Handle::decode(r, &mut ())]
}
}

impl<S> Encode<S> for &mut $oty {
fn encode(self, w: &mut Writer, s: &mut S) {
self.handle.encode(w, s);
}
}

impl<'s, S: server::Types> DecodeMut<'_, 's, HandleStore<server::MarkedTypes<S>>>
for &'s mut Marked<S::$oty, $oty>
{
fn decode(
r: &mut Reader<'_>,
s: &'s mut HandleStore<server::MarkedTypes<S>>
) -> Self {
&mut s.$oty[handle::Handle::decode(r, &mut ())]
}
}

impl<S: server::Types> Encode<HandleStore<server::MarkedTypes<S>>>
for Marked<S::$oty, $oty>
{
fn encode(self, w: &mut Writer, s: &mut HandleStore<server::MarkedTypes<S>>) {
s.$oty.alloc(self).encode(w, s);
}
}

impl<S> DecodeMut<'_, '_, S> for $oty {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
$oty {
Expand All @@ -145,22 +94,6 @@ macro_rules! define_handles {
}
}

impl<S: server::Types> DecodeMut<'_, '_, HandleStore<server::MarkedTypes<S>>>
for Marked<S::$ity, $ity>
{
fn decode(r: &mut Reader<'_>, s: &mut HandleStore<server::MarkedTypes<S>>) -> Self {
s.$ity.copy(handle::Handle::decode(r, &mut ()))
}
}

impl<S: server::Types> Encode<HandleStore<server::MarkedTypes<S>>>
for Marked<S::$ity, $ity>
{
fn encode(self, w: &mut Writer, s: &mut HandleStore<server::MarkedTypes<S>>) {
s.$ity.alloc(self).encode(w, s);
}
}

impl<S> DecodeMut<'_, '_, S> for $ity {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
$ity {
Expand All @@ -172,15 +105,7 @@ macro_rules! define_handles {
)*
}
}
define_handles! {
'owned:
FreeFunctions,
TokenStream,
SourceFile,

'interned:
Span,
}
with_api_handle_types!(define_client_handles);

// FIXME(eddyb) generate these impls by pattern-matching on the
// names of methods - also could use the presence of `fn drop`
Expand Down
17 changes: 17 additions & 0 deletions library/proc_macro/src/bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ macro_rules! with_api {
};
}

// Similar to `with_api`, but only lists the types requiring handles, and they
// are divided into the two storage categories.
macro_rules! with_api_handle_types {
($m:ident) => {
$m! {
'owned:
FreeFunctions,
TokenStream,
SourceFile,

'interned:
Span,
// Symbol is handled manually
}
};
}

// FIXME(eddyb) this calls `encode` for each argument, but in reverse,
// to match the ordering in `reverse_decode`.
macro_rules! reverse_encode {
Expand Down
75 changes: 73 additions & 2 deletions library/proc_macro/src/bridge/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,79 @@ use super::*;
use std::cell::Cell;
use std::marker::PhantomData;

// FIXME(eddyb) generate the definition of `HandleStore` in `server.rs`.
use super::client::HandleStore;
macro_rules! define_server_handles {
(
'owned: $($oty:ident,)*
'interned: $($ity:ident,)*
) => {
#[allow(non_snake_case)]
pub(super) struct HandleStore<S: Types> {
$($oty: handle::OwnedStore<S::$oty>,)*
$($ity: handle::InternedStore<S::$ity>,)*
}

impl<S: Types> HandleStore<S> {
fn new(handle_counters: &'static client::HandleCounters) -> Self {
HandleStore {
$($oty: handle::OwnedStore::new(&handle_counters.$oty),)*
$($ity: handle::InternedStore::new(&handle_counters.$ity),)*
}
}
}

$(
impl<S: Types> Encode<HandleStore<MarkedTypes<S>>> for Marked<S::$oty, client::$oty> {
fn encode(self, w: &mut Writer, s: &mut HandleStore<MarkedTypes<S>>) {
s.$oty.alloc(self).encode(w, s);
}
}

impl<S: Types> DecodeMut<'_, '_, HandleStore<MarkedTypes<S>>>
for Marked<S::$oty, client::$oty>
{
fn decode(r: &mut Reader<'_>, s: &mut HandleStore<MarkedTypes<S>>) -> Self {
s.$oty.take(handle::Handle::decode(r, &mut ()))
}
}

impl<'s, S: Types> Decode<'_, 's, HandleStore<MarkedTypes<S>>>
for &'s Marked<S::$oty, client::$oty>
{
fn decode(r: &mut Reader<'_>, s: &'s HandleStore<MarkedTypes<S>>) -> Self {
&s.$oty[handle::Handle::decode(r, &mut ())]
}
}

impl<'s, S: Types> DecodeMut<'_, 's, HandleStore<MarkedTypes<S>>>
for &'s mut Marked<S::$oty, client::$oty>
{
fn decode(
r: &mut Reader<'_>,
s: &'s mut HandleStore<MarkedTypes<S>>
) -> Self {
&mut s.$oty[handle::Handle::decode(r, &mut ())]
}
}
)*

$(
impl<S: Types> Encode<HandleStore<MarkedTypes<S>>> for Marked<S::$ity, client::$ity> {
fn encode(self, w: &mut Writer, s: &mut HandleStore<MarkedTypes<S>>) {
s.$ity.alloc(self).encode(w, s);
}
}

impl<S: Types> DecodeMut<'_, '_, HandleStore<MarkedTypes<S>>>
for Marked<S::$ity, client::$ity>
{
fn decode(r: &mut Reader<'_>, s: &mut HandleStore<MarkedTypes<S>>) -> Self {
s.$ity.copy(handle::Handle::decode(r, &mut ()))
}
}
)*
}
}
with_api_handle_types!(define_server_handles);

pub trait Types {
type FreeFunctions: 'static;
Expand Down
8 changes: 4 additions & 4 deletions library/proc_macro/src/bridge/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,18 @@ impl<S> Encode<S> for Symbol {
}
}

impl<S: server::Server> DecodeMut<'_, '_, client::HandleStore<server::MarkedTypes<S>>>
impl<S: server::Server> DecodeMut<'_, '_, server::HandleStore<server::MarkedTypes<S>>>
for Marked<S::Symbol, Symbol>
{
fn decode(r: &mut Reader<'_>, s: &mut client::HandleStore<server::MarkedTypes<S>>) -> Self {
fn decode(r: &mut Reader<'_>, s: &mut server::HandleStore<server::MarkedTypes<S>>) -> Self {
Mark::mark(S::intern_symbol(<&str>::decode(r, s)))
}
}

impl<S: server::Server> Encode<client::HandleStore<server::MarkedTypes<S>>>
impl<S: server::Server> Encode<server::HandleStore<server::MarkedTypes<S>>>
for Marked<S::Symbol, Symbol>
{
fn encode(self, w: &mut Writer, s: &mut client::HandleStore<server::MarkedTypes<S>>) {
fn encode(self, w: &mut Writer, s: &mut server::HandleStore<server::MarkedTypes<S>>) {
S::with_symbol_string(&self.unmark(), |sym| sym.encode(w, s))
}
}
Expand Down