about summary refs log tree commit diff
path: root/library/proc_macro/src/bridge/mod.rs
AgeCommit message (Collapse)AuthorLines
2025-06-14Remove all support for wasm's legacy ABIbjorn3-3/+0
2025-04-11Replace proc_macro::SourceFile by Span::{file, local_file}.Mara Bos-8/+2
2025-04-11Remove proc_macro::SourceFile::is_real().Mara Bos-1/+0
2025-04-09update cfgsBoxy-1/+0
2025-03-25allow wasm_c_abi in proc_macro bridgeRalf Jung-0/+4
2024-07-29Reformat `use` declarations.Nicholas Nethercote-8/+4
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-03-23proc_macro: simplify bridge statejoboet-3/+1
2024-03-01Move `HandleStore` into `server.rs`.Nicholas Nethercote-0/+17
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`.
2024-02-15Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.Nicholas Nethercote-2/+6
This mostly works well, and eliminates a couple of delayed bugs. One annoying thing is that we should really also add an `ErrorGuaranteed` to `proc_macro::bridge::LitKind::Err`. But that's difficult because `proc_macro` doesn't have access to `ErrorGuaranteed`, so we have to fake it.
2024-01-31Switch OwnedStore handle count to AtomicU32GnomedDev-1/+0
2023-12-11Add support for `--env` on `tracked_env::var`Guillaume Gomez-0/+1
2023-06-20Add `Span::{line, column}`Jacob Pratt-0/+2
2023-06-20`Span::{before, after}` → `Span::{start, end}`Jacob Pratt-2/+2
2023-06-20Remove `LineColumn`, `Span::start`, `Span::end`Jacob Pratt-5/+1
2023-05-02fix TODO commentsDeadbeef-0/+4
2023-03-11Renamed to byte_range and changed Range generics [skip ci]Michael van Straten-2/+1
2023-03-10added byte position range for proc_macro::SpanMichael van Straten-0/+7
2022-08-06proc_macro/bridge: send diagnostics over the bridge as a structNika Layzell-16/+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-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-30/+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-11/+22
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-0/+2
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-17/+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-13/+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-6/+6
2022-06-25proc_macro: cache static spans in client's thread-local stateNika Layzell-11/+39
This greatly improves the performance of the very frequently called `call_site()` macro when running in a cross-thread configuration.
2022-06-17review fixupsNika Layzell-29/+24
2022-06-17proc_macro: reduce the number of messages required to create, extend, and ↵Nika Layzell-16/+12
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/+15
2022-05-27proc_macro: don't pass a client-side function pointer through the server.Eduard-Mihai Burtescu-0/+2
2022-05-27Remove unnecessary blank line.Nicholas Nethercote-1/+0
2022-05-27Add some comments about `_marker` fields.Nicholas Nethercote-1/+3
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-2/+2
`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-04-06Use PhantomData directly in Bridgebjorn3-2/+3
2022-03-25Avoid negative impls in the bridgebjorn3-3/+2
2021-12-14made compiler happyAnuvrat-4/+4
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-02add track_path::path fn for proc-macro usageBernhard Schuster-0/+1
Ref #73921
2021-06-09Add proc_macro::Span::{before, after}.Mara Bos-0/+2
2021-05-19impl FromStr for proc_macro::LiteralDavid Tolnay-0/+14
2021-05-12Implement span quoting for proc-macrosAaron Hill-0/+3
This PR implements span quoting, allowing proc-macros to produce spans pointing *into their own crate*. This is used by the unstable `proc_macro::quote!` macro, allowing us to get error messages like this: ``` error[E0412]: cannot find type `MissingType` in this scope --> $DIR/auxiliary/span-from-proc-macro.rs:37:20 | LL | pub fn error_from_attribute(_args: TokenStream, _input: TokenStream) -> TokenStream { | ----------------------------------------------------------------------------------- in this expansion of procedural macro `#[error_from_attribute]` ... LL | field: MissingType | ^^^^^^^^^^^ not found in this scope | ::: $DIR/span-from-proc-macro.rs:8:1 | LL | #[error_from_attribute] | ----------------------- in this macro invocation ``` Here, `MissingType` occurs inside the implementation of the proc-macro `#[error_from_attribute]`. Previosuly, this would always result in a span pointing at `#[error_from_attribute]` This will make many proc-macro-related error message much more useful - when a proc-macro generates code containing an error, users will get an error message pointing directly at that code (within the macro definition), instead of always getting a span pointing at the macro invocation site. This is implemented as follows: * When a proc-macro crate is being *compiled*, it causes the `quote!` macro to get run. This saves all of the sapns in the input to `quote!` into the metadata of *the proc-macro-crate* (which we are currently compiling). The `quote!` macro then expands to a call to `proc_macro::Span::recover_proc_macro_span(id)`, where `id` is an opaque identifier for the span in the crate metadata. * When the same proc-macro crate is *run* (e.g. it is loaded from disk and invoked by some consumer crate), the call to `proc_macro::Span::recover_proc_macro_span` causes us to load the span from the proc-macro crate's metadata. The proc-macro then produces a `TokenStream` containing a `Span` pointing into the proc-macro crate itself. The recursive nature of 'quote!' can be difficult to understand at first. The file `src/test/ui/proc-macro/quote-debug.stdout` shows the output of the `quote!` macro, which should make this eaier to understand. This PR also supports custom quoting spans in custom quote macros (e.g. the `quote` crate). All span quoting goes through the `proc_macro::quote_span` method, which can be called by a custom quote macro to perform span quoting. An example of this usage is provided in `src/test/ui/proc-macro/auxiliary/custom-quote.rs` Custom quoting currently has a few limitations: In order to quote a span, we need to generate a call to `proc_macro::Span::recover_proc_macro_span`. However, proc-macros support renaming the `proc_macro` crate, so we can't simply hardcode this path. Previously, the `quote_span` method used the path `crate::Span` - however, this only works when it is called by the builtin `quote!` macro in the same crate. To support being called from arbitrary crates, we need access to the name of the `proc_macro` crate to generate a path. This PR adds an additional argument to `quote_span` to specify the name of the `proc_macro` crate. Howver, this feels kind of hacky, and we may want to change this before stabilizing anything quote-related. Additionally, using `quote_span` currently requires enabling the `proc_macro_internals` feature. The builtin `quote!` macro has an `#[allow_internal_unstable]` attribute, but this won't work for custom quote implementations. This will likely require some additional tricks to apply `allow_internal_unstable` to the span of `proc_macro::Span::recover_proc_macro_span`.
2020-08-30Add `-Z proc-macro-backtrace` to allow showing proc-macro panicsAaron Hill-0/+3
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/+407