rust/library/proc_macro/src/bridge
Nika Layzell efda49712b proc_macro/bridge: use the cross-thread executor for nested proc-macros
While working on some other changes in the bridge, I noticed that when
running a nested proc-macro (which is currently only possible using
the unstable `TokenStream::expand_expr`), any symbols held by the
proc-macro client would be invalidated, as the same thread would be used
for the nested macro by default, and the interner doesn't handle nested
use.

After discussing with @eddyb, we decided the best approach might be to
force the use of the cross-thread executor for nested invocations, as it
will never re-use thread-local storage, avoiding the issue. This
shouldn't impact performance, as expand_expr is still unstable, and
infrequently used.

This was chosen rather than making the client symbol interner handle
nested invocations, as that would require replacing the internal
interner `Vec` with a `BTreeMap` (as valid symbol id ranges could now be
disjoint), and the symbol interner is known to be fairly perf-sensitive.

This patch adds checks to the execution strategy to use the cross-thread
executor when doing nested invocations. An alternative implementation
strategy could be to track this information in the `ExtCtxt`, however a
thread-local in the `proc_macro` crate was chosen to add an assertion so
that `rust-analyzer` is aware of the issue if it implements
`expand_expr` in the future.

r? @eddyb
2022-09-04 14:06:26 -04:00
..
arena.rs proc_macro: stop using a remote object handle for Ident 2022-07-18 12:59:14 -04:00
buffer.rs Inline bridge::Buffer methods. 2022-06-01 09:21:35 +10:00
client.rs proc_macro/bridge: send diagnostics over the bridge as a struct 2022-08-06 15:49:43 -04:00
closure.rs Add some comments about _marker fields. 2022-05-27 15:58:35 +10:00
fxhash.rs proc_macro: use fxhash within the proc_macro crate 2022-07-18 12:59:14 -04:00
handle.rs proc_macro: use fxhash within the proc_macro crate 2022-07-18 12:59:14 -04:00
mod.rs proc_macro/bridge: send diagnostics over the bridge as a struct 2022-08-06 15:49:43 -04:00
rpc.rs review fixups 2022-06-17 22:10:07 -04:00
scoped_cell.rs Remove some unnecessary rustc_allow_const_fn_unstable attributes. 2022-05-13 16:01:18 +10:00
selfless_reify.rs proc_macro: cache static spans in client's thread-local state 2022-06-25 10:28:11 -04:00
server.rs proc_macro/bridge: use the cross-thread executor for nested proc-macros 2022-09-04 14:06:26 -04:00
symbol.rs proc_macro: stop using a remote object handle for Ident 2022-07-18 12:59:14 -04:00