summary refs log tree commit diff
path: root/library/proc_macro/src/bridge
AgeCommit message (Collapse)AuthorLines
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
2021-07-02add track_path::path fn for proc-macro usageBernhard Schuster-0/+1
Ref #73921
2021-07-01proc_macro/bridge: Remove dead code Slice typeJade-29/+0
See https://github.com/rust-lang/rust/pull/85390#discussion_r662464868
2021-06-25Fix a few misspellings.Eric Huss-1/+1
2021-06-09Add proc_macro::Span::{before, after}.Mara Bos-0/+2
2021-05-29Write primitive types via array buffersMark Rousskov-2/+17
This allows a more efficient implementation (avoiding a fallback to memmove, which is not optimal for short writes). This saves 0.29% on diesel.
2021-05-29Switch to reserve over extend_from_sliceMark Rousskov-25/+21
This is a 0.15% win on diesel.
2021-05-29Specialize single-element writes to bufferMark Rousskov-1/+16
copy_from_slice generally falls back to memcpy/memmove, which is much more expensive than we need to write a single element in. This saves 0.26% instructions on the diesel benchmark.
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-11-19Bump bootstrap compiler versionJake Goulding-12/+6
2020-10-21switch allow_internal_unstable const fns to rustc_allow_const_fn_unstableFlorian Warzecha-6/+12
2020-09-22Update library functions with stability attributesDylan MacKenzie-0/+6
This may not be strictly minimal, but all unstable functions also need a `rustc_const_unstable` attribute.
2020-09-03Respect `-Z proc-macro-backtrace` flag for panics inside libproc_macroAaron Hill-3/+2
Fixes #76270 Previously, any panic occuring during a call to a libproc_macro method (e.g. calling `Ident::new` with an invalid identifier) would always cause an ICE message to be printed.
2020-08-30Add `-Z proc-macro-backtrace` to allow showing proc-macro panicsAaron Hill-8/+39
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/+1840