about summary refs log tree commit diff
path: root/library/proc_macro/src/bridge
AgeCommit message (Collapse)AuthorLines
2023-01-14Use associated items of `char` instead of freestanding items in `core::char`Lukas Markeffsky-1/+0
2022-12-30Replace libstd, libcore, liballoc in line comments.jonathanCogan-2/+2
2022-12-30Replace libstd, libcore, liballoc in docs.jonathanCogan-3/+3
2022-10-05A tiny fix for `define_client_side`.Nicholas Nethercote-2/+2
The return type can only appear once.
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-20/+13
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: Move subspan to be a method on Span in the bridgeNika Layzell-1/+1
This method is still only used for Literal::subspan, however the implementation only depends on the Span component, so it is simpler and more efficient for now to pass down only the information that is needed. In the future, if more information about the Literal is required in the implementation (e.g. to validate that spans line up as expected with source text), that extra information can be added back with extra arguments.
2022-07-18proc_macro: stop using a remote object handle for LiteralNika Layzell-51/+46
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-13/+364
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-07-18proc_macro: use fxhash within the proc_macro crateNika Layzell-20/+125
Unfortunately, as it is difficult to depend on crates from within proc_macro, this is done by vendoring a copy of the hasher as a module rather than depending on the rustc_hash crate. This probably doesn't have a substantial impact up-front, however will be more relevant once symbols are interned within the proc_macro client.
2022-06-28review changesNika Layzell-26/+27
longer names for RPC generics and reduced dependency on macros in the server.
2022-06-26proc_macro: stop using a remote object handle for GroupNika Layzell-25/+30
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-15/+15
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-30/+18
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-85/+169
This greatly improves the performance of the very frequently called `call_site()` macro when running in a cross-thread configuration.
2022-06-19Auto merge of #98224 - eddyb:proc-macro-spurious-repr, r=bjorn3bors-3/+0
proc_macro/bridge: remove `#[repr(C)]` from non-ABI-relevant types. Not sure how this happened, maybe some of these were passed through the bridge a long time ago? r? `@bjorn3`
2022-06-18proc_macro/bridge: remove `#[repr(C)]` from non-ABI-relevant types.Eduard-Mihai Burtescu-3/+0
2022-06-17review fixupsNika Layzell-52/+24
2022-06-17Move empty final TokenStream handling to server side of bridgeNika Layzell-14/+16
2022-06-17proc_macro: reduce the number of messages required to create, extend, and ↵Nika Layzell-28/+20
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-06-16proc_macro: use macros to simplify aggregate Mark/Unmark definitionsNika Layzell-24/+34
2022-06-14proc_macro: support encoding/decoding Vec<T>Nika Layzell-0/+35
2022-06-14proc_macro: support encoding/decoding structs with type parametersNika Layzell-4/+6
2022-06-13proc_macro: bypass RandomState to remove ASLR-like effects.Eduard-Mihai Burtescu-3/+19
2022-06-01Inline `bridge::Buffer` methods.Nicholas Nethercote-0/+13
This fixes a performance regression caused by making `Buffer` non-generic in #97004.
2022-05-27proc_macro: don't pass a client-side function pointer through the server.Eduard-Mihai Burtescu-90/+163
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-27Remove unnecessary blank line.Nicholas Nethercote-1/+0
2022-05-27Rename `b` as `buf` in several places.Nicholas Nethercote-30/+30
Because it's easy to confuse with `bridge`.
2022-05-27Add some comments about `_marker` fields.Nicholas Nethercote-4/+14
There is some non-obvious information required to understand them.
2022-05-27Clarify a comment.Nicholas Nethercote-1/+1
`reverse_encode` isn't necessary to please the borrow checker, it's to match the ordering done by `reverse_decode`.
2022-05-27Make `Buffer<T>` non-generic.Nicholas Nethercote-46/+46
`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-05-27Add some comments.Nicholas Nethercote-0/+3
2022-05-27Fix a typo in a comment.Nicholas Nethercote-1/+1
2022-05-13Remove some unnecessary `rustc_allow_const_fn_unstable` attributes.Nicholas Nethercote-6/+0
2022-04-06Use PhantomData directly in Bridgebjorn3-3/+11
2022-03-25Avoid negative impls in the bridgebjorn3-20/+32
2022-03-25Remove usage of extern_types feature gatebjorn3-7/+8
2022-03-25Remove usage of panic_update_hook feature gatebjorn3-2/+3
2022-01-08Change panic::update_hook to simplify usageBadel2-10/+8
And to remove possibility of panics while changing the panic handler, because that resulted in a double panic.
2022-01-07Implement panic::update_hookBadel2-10/+11
2021-12-14made compiler happyAnuvrat-10/+10
2021-11-12proc_macro: Add an expand_expr method to TokenStreamNika Layzell-0/+1
This feature is aimed at giving proc macros access to powers similar to those used by builtin macros such as `format_args!` or `concat!`. These macros are able to accept macros in place of string literal parameters, such as the format string, as they perform recursive macro expansion while being expanded. This can be especially useful in many cases thanks to helper macros like `concat!`, `stringify!` and `include_str!` which are often used to construct string literals at compile-time in user code. For now, this method only allows expanding macros which produce literals, although more expresisons will be supported before the method is stabilized.
2021-09-10Rollup merge of #86165 - m-ou-se:proc-macro-span-shrink, r=dtolnayManish Goregaokar-0/+2
Add proc_macro::Span::{before, after}. This adds `proc_macro::Span::before()` and `proc_macro::Span::after()` to get a zero width span at the start or end of the span. These are equivalent to rustc's `Span::shrink_to_lo()` and `Span::shrink_to_hi()` but with a less cryptic name. They are useful when generating diagnostlics like "missing \<thing\> after \<thing\>". E.g. ```rust syn::Error::new(ident.span().after(), "missing `:` after field name").into_compile_error() ```
2021-08-03Remove space after negative sign in Literal to_stringDavid Tolnay-0/+1
2021-07-29Fix may not to appropriate might not or must notAli Malik-1/+1
2021-07-03Rollup merge of #84029 - drahnr:master, r=petrochenkovYuki Okushi-0/+1
add `track_path::path` fn for usage in `proc_macro`s Adds a way to declare a dependency on external files without including them, to either re-trigger the build of a file as well as covering the use case of including dependencies within the `rustc` invocation, such that tools like `sccache`/`cachepot` are able to handle references to external files which are not included. Ref #73921