Skip to content

Commit 7709161

Browse files
authored
Unrolled build for rust-lang#121835
Rollup merge of rust-lang#121835 - nnethercote:mv-HandleStore, r=bjorn3 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`. r? ```@bjorn3```
2 parents 2e3581b + 392159b commit 7709161

File tree

4 files changed

+99
-86
lines changed

4 files changed

+99
-86
lines changed

library/proc_macro/src/bridge/client.rs

+5-80
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ use super::*;
55
use std::marker::PhantomData;
66
use std::sync::atomic::AtomicU32;
77

8-
macro_rules! define_handles {
8+
macro_rules! define_client_handles {
99
(
1010
'owned: $($oty:ident,)*
1111
'interned: $($ity:ident,)*
1212
) => {
1313
#[repr(C)]
1414
#[allow(non_snake_case)]
15-
pub struct HandleCounters {
16-
$($oty: AtomicU32,)*
17-
$($ity: AtomicU32,)*
15+
pub(super) struct HandleCounters {
16+
$(pub(super) $oty: AtomicU32,)*
17+
$(pub(super) $ity: AtomicU32,)*
1818
}
1919

2020
impl HandleCounters {
@@ -29,22 +29,6 @@ macro_rules! define_handles {
2929
}
3030
}
3131

32-
// FIXME(eddyb) generate the definition of `HandleStore` in `server.rs`.
33-
#[allow(non_snake_case)]
34-
pub(super) struct HandleStore<S: server::Types> {
35-
$($oty: handle::OwnedStore<S::$oty>,)*
36-
$($ity: handle::InternedStore<S::$ity>,)*
37-
}
38-
39-
impl<S: server::Types> HandleStore<S> {
40-
pub(super) fn new(handle_counters: &'static HandleCounters) -> Self {
41-
HandleStore {
42-
$($oty: handle::OwnedStore::new(&handle_counters.$oty),)*
43-
$($ity: handle::InternedStore::new(&handle_counters.$ity),)*
44-
}
45-
}
46-
}
47-
4832
$(
4933
pub(crate) struct $oty {
5034
handle: handle::Handle,
@@ -72,53 +56,18 @@ macro_rules! define_handles {
7256
}
7357
}
7458

75-
impl<S: server::Types> DecodeMut<'_, '_, HandleStore<server::MarkedTypes<S>>>
76-
for Marked<S::$oty, $oty>
77-
{
78-
fn decode(r: &mut Reader<'_>, s: &mut HandleStore<server::MarkedTypes<S>>) -> Self {
79-
s.$oty.take(handle::Handle::decode(r, &mut ()))
80-
}
81-
}
82-
8359
impl<S> Encode<S> for &$oty {
8460
fn encode(self, w: &mut Writer, s: &mut S) {
8561
self.handle.encode(w, s);
8662
}
8763
}
8864

89-
impl<'s, S: server::Types> Decode<'_, 's, HandleStore<server::MarkedTypes<S>>>
90-
for &'s Marked<S::$oty, $oty>
91-
{
92-
fn decode(r: &mut Reader<'_>, s: &'s HandleStore<server::MarkedTypes<S>>) -> Self {
93-
&s.$oty[handle::Handle::decode(r, &mut ())]
94-
}
95-
}
96-
9765
impl<S> Encode<S> for &mut $oty {
9866
fn encode(self, w: &mut Writer, s: &mut S) {
9967
self.handle.encode(w, s);
10068
}
10169
}
10270

103-
impl<'s, S: server::Types> DecodeMut<'_, 's, HandleStore<server::MarkedTypes<S>>>
104-
for &'s mut Marked<S::$oty, $oty>
105-
{
106-
fn decode(
107-
r: &mut Reader<'_>,
108-
s: &'s mut HandleStore<server::MarkedTypes<S>>
109-
) -> Self {
110-
&mut s.$oty[handle::Handle::decode(r, &mut ())]
111-
}
112-
}
113-
114-
impl<S: server::Types> Encode<HandleStore<server::MarkedTypes<S>>>
115-
for Marked<S::$oty, $oty>
116-
{
117-
fn encode(self, w: &mut Writer, s: &mut HandleStore<server::MarkedTypes<S>>) {
118-
s.$oty.alloc(self).encode(w, s);
119-
}
120-
}
121-
12271
impl<S> DecodeMut<'_, '_, S> for $oty {
12372
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
12473
$oty {
@@ -145,22 +94,6 @@ macro_rules! define_handles {
14594
}
14695
}
14796

148-
impl<S: server::Types> DecodeMut<'_, '_, HandleStore<server::MarkedTypes<S>>>
149-
for Marked<S::$ity, $ity>
150-
{
151-
fn decode(r: &mut Reader<'_>, s: &mut HandleStore<server::MarkedTypes<S>>) -> Self {
152-
s.$ity.copy(handle::Handle::decode(r, &mut ()))
153-
}
154-
}
155-
156-
impl<S: server::Types> Encode<HandleStore<server::MarkedTypes<S>>>
157-
for Marked<S::$ity, $ity>
158-
{
159-
fn encode(self, w: &mut Writer, s: &mut HandleStore<server::MarkedTypes<S>>) {
160-
s.$ity.alloc(self).encode(w, s);
161-
}
162-
}
163-
16497
impl<S> DecodeMut<'_, '_, S> for $ity {
16598
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
16699
$ity {
@@ -172,15 +105,7 @@ macro_rules! define_handles {
172105
)*
173106
}
174107
}
175-
define_handles! {
176-
'owned:
177-
FreeFunctions,
178-
TokenStream,
179-
SourceFile,
180-
181-
'interned:
182-
Span,
183-
}
108+
with_api_handle_types!(define_client_handles);
184109

185110
// FIXME(eddyb) generate these impls by pattern-matching on the
186111
// names of methods - also could use the presence of `fn drop`

library/proc_macro/src/bridge/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,23 @@ macro_rules! with_api {
113113
};
114114
}
115115

116+
// Similar to `with_api`, but only lists the types requiring handles, and they
117+
// are divided into the two storage categories.
118+
macro_rules! with_api_handle_types {
119+
($m:ident) => {
120+
$m! {
121+
'owned:
122+
FreeFunctions,
123+
TokenStream,
124+
SourceFile,
125+
126+
'interned:
127+
Span,
128+
// Symbol is handled manually
129+
}
130+
};
131+
}
132+
116133
// FIXME(eddyb) this calls `encode` for each argument, but in reverse,
117134
// to match the ordering in `reverse_decode`.
118135
macro_rules! reverse_encode {

library/proc_macro/src/bridge/server.rs

+73-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,79 @@ use super::*;
55
use std::cell::Cell;
66
use std::marker::PhantomData;
77

8-
// FIXME(eddyb) generate the definition of `HandleStore` in `server.rs`.
9-
use super::client::HandleStore;
8+
macro_rules! define_server_handles {
9+
(
10+
'owned: $($oty:ident,)*
11+
'interned: $($ity:ident,)*
12+
) => {
13+
#[allow(non_snake_case)]
14+
pub(super) struct HandleStore<S: Types> {
15+
$($oty: handle::OwnedStore<S::$oty>,)*
16+
$($ity: handle::InternedStore<S::$ity>,)*
17+
}
18+
19+
impl<S: Types> HandleStore<S> {
20+
fn new(handle_counters: &'static client::HandleCounters) -> Self {
21+
HandleStore {
22+
$($oty: handle::OwnedStore::new(&handle_counters.$oty),)*
23+
$($ity: handle::InternedStore::new(&handle_counters.$ity),)*
24+
}
25+
}
26+
}
27+
28+
$(
29+
impl<S: Types> Encode<HandleStore<MarkedTypes<S>>> for Marked<S::$oty, client::$oty> {
30+
fn encode(self, w: &mut Writer, s: &mut HandleStore<MarkedTypes<S>>) {
31+
s.$oty.alloc(self).encode(w, s);
32+
}
33+
}
34+
35+
impl<S: Types> DecodeMut<'_, '_, HandleStore<MarkedTypes<S>>>
36+
for Marked<S::$oty, client::$oty>
37+
{
38+
fn decode(r: &mut Reader<'_>, s: &mut HandleStore<MarkedTypes<S>>) -> Self {
39+
s.$oty.take(handle::Handle::decode(r, &mut ()))
40+
}
41+
}
42+
43+
impl<'s, S: Types> Decode<'_, 's, HandleStore<MarkedTypes<S>>>
44+
for &'s Marked<S::$oty, client::$oty>
45+
{
46+
fn decode(r: &mut Reader<'_>, s: &'s HandleStore<MarkedTypes<S>>) -> Self {
47+
&s.$oty[handle::Handle::decode(r, &mut ())]
48+
}
49+
}
50+
51+
impl<'s, S: Types> DecodeMut<'_, 's, HandleStore<MarkedTypes<S>>>
52+
for &'s mut Marked<S::$oty, client::$oty>
53+
{
54+
fn decode(
55+
r: &mut Reader<'_>,
56+
s: &'s mut HandleStore<MarkedTypes<S>>
57+
) -> Self {
58+
&mut s.$oty[handle::Handle::decode(r, &mut ())]
59+
}
60+
}
61+
)*
62+
63+
$(
64+
impl<S: Types> Encode<HandleStore<MarkedTypes<S>>> for Marked<S::$ity, client::$ity> {
65+
fn encode(self, w: &mut Writer, s: &mut HandleStore<MarkedTypes<S>>) {
66+
s.$ity.alloc(self).encode(w, s);
67+
}
68+
}
69+
70+
impl<S: Types> DecodeMut<'_, '_, HandleStore<MarkedTypes<S>>>
71+
for Marked<S::$ity, client::$ity>
72+
{
73+
fn decode(r: &mut Reader<'_>, s: &mut HandleStore<MarkedTypes<S>>) -> Self {
74+
s.$ity.copy(handle::Handle::decode(r, &mut ()))
75+
}
76+
}
77+
)*
78+
}
79+
}
80+
with_api_handle_types!(define_server_handles);
1081

1182
pub trait Types {
1283
type FreeFunctions: 'static;

library/proc_macro/src/bridge/symbol.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,18 @@ impl<S> Encode<S> for Symbol {
109109
}
110110
}
111111

112-
impl<S: server::Server> DecodeMut<'_, '_, client::HandleStore<server::MarkedTypes<S>>>
112+
impl<S: server::Server> DecodeMut<'_, '_, server::HandleStore<server::MarkedTypes<S>>>
113113
for Marked<S::Symbol, Symbol>
114114
{
115-
fn decode(r: &mut Reader<'_>, s: &mut client::HandleStore<server::MarkedTypes<S>>) -> Self {
115+
fn decode(r: &mut Reader<'_>, s: &mut server::HandleStore<server::MarkedTypes<S>>) -> Self {
116116
Mark::mark(S::intern_symbol(<&str>::decode(r, s)))
117117
}
118118
}
119119

120-
impl<S: server::Server> Encode<client::HandleStore<server::MarkedTypes<S>>>
120+
impl<S: server::Server> Encode<server::HandleStore<server::MarkedTypes<S>>>
121121
for Marked<S::Symbol, Symbol>
122122
{
123-
fn encode(self, w: &mut Writer, s: &mut client::HandleStore<server::MarkedTypes<S>>) {
123+
fn encode(self, w: &mut Writer, s: &mut server::HandleStore<server::MarkedTypes<S>>) {
124124
S::with_symbol_string(&self.unmark(), |sym| sym.encode(w, s))
125125
}
126126
}

0 commit comments

Comments
 (0)