about summary refs log tree commit diff
path: root/library/proc_macro/src/bridge/server.rs
AgeCommit message (Collapse)AuthorLines
2022-12-30Replace libstd, libcore, liballoc in line comments.jonathanCogan-1/+1
2022-09-04proc_macro/bridge: use the cross-thread executor for nested proc-macrosNika Layzell-1/+36
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-08-06proc_macro/bridge: send diagnostics over the bridge as a structNika Layzell-2/+0
This removes some RPC when creating and emitting diagnostics, and simplifies the bridge slightly. After this change, there are no remaining methods which take advantage of the support for `&mut` references to objects in the store as arguments, meaning that support for them could technically be removed if we wanted. The only remaining uses of immutable references into the store are `TokenStream` and `SourceFile`.
2022-07-29proc_macro: use crossbeam channels for the proc_macro cross-thread bridgeNika Layzell-72/+64
This is done by having the crossbeam dependency inserted into the proc_macro server code from the server side, to avoid adding a dependency to proc_macro. In addition, this introduces a -Z command-line option which will switch rustc to run proc-macros using this cross-thread executor. With the changes to the bridge in #98186, #98187, #98188 and #98189, the performance of the executor should be much closer to same-thread execution. In local testing, the crossbeam executor was substantially more performant than either of the two existing CrossThread strategies, so they have been removed to keep things simple.
2022-07-18proc_macro: stop using a remote object handle for LiteralNika Layzell-1/+0
This builds on the symbol infrastructure built for `Ident` to replicate the `LitKind` and `Lit` structures in rustc within the `proc_macro` client, allowing literals to be fully created and interacted with from the client thread. Only parsing and subspan operations still require sync RPC.
2022-07-18proc_macro: stop using a remote object handle for IdentNika Layzell-1/+15
Doing this for all unicode identifiers would require a dependency on `unicode-normalization` and `rustc_lexer`, which is currently not possible for `proc_macro` due to it being built concurrently with `std` and `core`. Instead, ASCII identifiers are validated locally, and an RPC message is used to validate unicode identifiers when needed. String values are interned on the both the server and client when deserializing, to avoid unnecessary copies and keep Ident cheap to copy and move. This appears to be important for performance. The client-side interner is based roughly on the one from rustc_span, and uses an arena inspired by rustc_arena. RPC messages passing symbols always include the full value. This could potentially be optimized in the future if it is revealed to be a performance bottleneck. Despite now having a relevant implementaion of Display for Ident, ToString is still specialized, as it is a hot-path for this object. The symbol infrastructure will also be used for literals in the next part.
2022-06-26proc_macro: stop using a remote object handle for GroupNika Layzell-1/+0
This greatly reduces round-trips to fetch relevant extra information about the token in proc macro code, and avoids RPC messages to create Group tokens.
2022-06-26proc_macro: stop using a remote object handle for PunctNika Layzell-1/+0
This greatly reduces round-trips to fetch relevant extra information about the token in proc macro code, and avoids RPC messages to create Punct tokens.
2022-06-26proc_macro: Rename ExpnContext to ExpnGlobals, and unify method on Server traitNika Layzell-17/+5
2022-06-25proc_macro: remove Context trait, and put span methods directly on ServerNika Layzell-13/+9
2022-06-25proc_macro: cache static spans in client's thread-local stateNika Layzell-14/+39
This greatly improves the performance of the very frequently called `call_site()` macro when running in a cross-thread configuration.
2022-06-17Move empty final TokenStream handling to server side of bridgeNika Layzell-6/+14
2022-06-17proc_macro: reduce the number of messages required to create, extend, and ↵Nika Layzell-2/+0
iterate TokenStreams This significantly reduces the cost of common interactions with TokenStream when running with the CrossThread execution strategy, by reducing the number of RPC calls required.
2022-05-27proc_macro: don't pass a client-side function pointer through the server.Eduard-Mihai Burtescu-55/+32
2022-05-27Cut down `associated_item`.Nicholas Nethercote-20/+18
The part of it dealing with types obfuscates and makes the code less concise. This commit removes that part.
2022-05-27Rename `b` as `buf` in several places.Nicholas Nethercote-14/+14
Because it's easy to confuse with `bridge`.
2022-05-27Make `Buffer<T>` non-generic.Nicholas Nethercote-15/+15
`u8` is the only type that makes sense for `T`, as demonstrated by the fact that several impls and functions are hardwired to `Buffer<u8>`.
2022-05-27Improve formatting in `associated_item!` definition.Nicholas Nethercote-24/+15
2022-04-06Use PhantomData directly in Bridgebjorn3-1/+8
2020-08-30Add `-Z proc-macro-backtrace` to allow showing proc-macro panicsAaron Hill-4/+30
Fixes #75050 Previously, we would unconditionally suppress the panic hook during proc-macro execution. This commit adds a new flag -Z proc-macro-backtrace, which allows running the panic hook for easier debugging.
2020-07-27mv std libs to library/mark-0/+322