about summary refs log tree commit diff
path: root/library/proc_macro/src
AgeCommit message (Collapse)AuthorLines
2023-02-12Auto merge of #105671 - lukas-code:depreciate-char, r=scottmcmbors-1/+0
Use associated items of `char` instead of freestanding items in `core::char` The associated functions and constants on `char` have been stable since 1.52 and the freestanding items have soft-deprecated since 1.62 (https://github.com/rust-lang/rust/pull/95566). This PR ~~marks them as "deprecated in future", similar to the integer and floating point modules (`core::{i32, f32}` etc)~~ replaces all uses of `core::char::*` with `char::*` to prepare for future deprecation of `core::char::*`.
2023-01-26Auto merge of #107318 - matthiaskrgr:rollup-776kd81, r=matthiaskrgrbors-1/+1
Rollup of 9 pull requests Successful merges: - #97373 (impl DispatchFromDyn for Cell and UnsafeCell) - #106625 (Remove backwards compat for LLVM 12 coverage format) - #106779 (Avoid __cxa_thread_atexit_impl on Emscripten) - #106811 (Append .dwp to the binary filename instead of replacing the existing extension.) - #106836 (Remove optimistic spinning from `mpsc::SyncSender`) - #106946 (implement Hash for proc_macro::LineColumn) - #107074 (remove unnecessary check for opaque types) - #107287 (Improve fn pointer notes) - #107304 (Use `can_eq` to compare types for default assoc type error) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-01-16implement Hash for proc_macro::LineColumnDavid Tolnay-1/+1
2023-01-14Use associated items of `char` instead of freestanding items in `core::char`Lukas Markeffsky-1/+0
2023-01-12Improve proc macro attribute diagnosticsmejrs-0/+1
2022-12-30Replace libstd, libcore, liballoc in line comments.jonathanCogan-2/+2
2022-12-30Replace libstd, libcore, liballoc in docs.jonathanCogan-3/+3
2022-12-12Add a "the" to proc_macro documentationest31-1/+1
2022-11-06Bump version placeholders to releaseMark Rousskov-1/+1
2022-10-18Stabilize proc_macro::Span::source_textest31-1/+1
Splits proc_macro::Span::source_text into a new feature gate and stabilizes it.
2022-10-05A tiny fix for `define_client_side`.Nicholas Nethercote-2/+2
The return type can only appear once.
2022-09-17Fix typo in proc_macro Span::eqjam1garner-1/+1
2022-09-12Rollup merge of #100767 - kadiwa4:escape_ascii, r=jackh726Dylan DPC-6/+1
Remove manual <[u8]>::escape_ascii `@rustbot` label: +C-cleanup
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-19use <[u8]>::escape_ascii instead of core::ascii::escape_defaultKaDiWa-6/+1
2022-08-06proc_macro/bridge: send diagnostics over the bridge as a structNika Layzell-34/+20
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-24Expose size_hint() for TokenStream's iteratorDavid Tolnay-0/+8
2022-07-20Rollup merge of #99516 - m-ou-se:proc-macro-tracked-tracking-issue, ↵Matthias Krüger-4/+4
r=Mark-Simulacrum Use new tracking issue for proc_macro::tracked_*.
2022-07-20Use new tracking issue for proc_macro::tracked_*.Mara Bos-4/+4
2022-07-18proc_macro: Move subspan to be a method on Span in the bridgeNika Layzell-7/+2
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-79/+156
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-29/+395
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: Specialize Punct::to_stringNika Layzell-0/+7
This was removed in a previous part, however it should be specialized for to_string performance and consistency.
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-28/+33
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-36/+45
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-34/+32
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-86/+170
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-67/+39
2022-06-17Move empty final TokenStream handling to server side of bridgeNika Layzell-14/+16
2022-06-17Try to reduce codegen complexity of TokenStream's FromIterator and Extend implsNika Layzell-16/+92
This is an experimental patch to try to reduce the codegen complexity of TokenStream's FromIterator and Extend implementations for downstream crates, by moving the core logic into a helper type. This might help improve build performance of crates which depend on proc_macro as iterators are used less, and the compiler may take less time to do things like attempt specializations or other iterator optimizations. The change intentionally sacrifices some optimization opportunities, such as using the specializations for collecting iterators derived from Vec::into_iter() into Vec. This is one of the simpler potential approaches to reducing the amount of code generated in crates depending on proc_macro, so it seems worth trying before other more-involved changes.
2022-06-17proc_macro: reduce the number of messages required to create, extend, and ↵Nika Layzell-52/+74
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-07Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakisbors-1/+0
Remove migrate borrowck mode Closes #58781 Closes #43234 # Stabilization proposal This PR proposes the stabilization of `#![feature(nll)]` and the removal of `-Z borrowck`. Current borrow checking behavior of item bodies is currently done by first infering regions *lexically* and reporting any errors during HIR type checking. If there *are* any errors, then MIR borrowck (NLL) never occurs. If there *aren't* any errors, then MIR borrowck happens and any errors there would be reported. This PR removes the lexical region check of item bodies entirely and only uses MIR borrowck. Because MIR borrowck could never *not* be run for a compiled program, this should not break any programs. It does, however, change diagnostics significantly and allows a slightly larger set of programs to compile. Tracking issue: #43234 RFC: https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md Version: 1.63 (2022-06-30 => beta, 2022-08-11 => stable). ## Motivation Over time, the Rust borrow checker has become "smarter" and thus allowed more programs to compile. There have been three different implementations: AST borrowck, MIR borrowck, and polonius (well, in progress). Additionally, there is the "lexical region resolver", which (roughly) solves the constraints generated through HIR typeck. It is not a full borrow checker, but does emit some errors. The AST borrowck was the original implementation of the borrow checker and was part of the initially stabilized Rust 1.0. In mid 2017, work began to implement the current MIR borrow checker and that effort ompleted by the end of 2017, for the most part. During 2018, efforts were made to migrate away from the AST borrow checker to the MIR borrow checker - eventually culminating into "migrate" mode - where HIR typeck with lexical region resolving following by MIR borrow checking - being active by default in the 2018 edition. In early 2019, migrate mode was turned on by default in the 2015 edition as well, but with MIR borrowck errors emitted as warnings. By late 2019, these warnings were upgraded to full errors. This was followed by the complete removal of the AST borrow checker. In the period since, various errors emitted by the MIR borrow checker have been improved to the point that they are mostly the same or better than those emitted by the lexical region resolver. While there do remain some degradations in errors (tracked under the [NLL-diagnostics tag](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3ANLL-diagnostics), those are sufficiently small and rare enough that increased flexibility of MIR borrow check-only is now a worthwhile tradeoff. ## What is stabilized As said previously, this does not fundamentally change the landscape of accepted programs. However, there are a [few](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3ANLL-fixed-by-NLL) cases where programs can compile under `feature(nll)`, but not otherwise. There are two notable patterns that are "fixed" by this stabilization. First, the `scoped_threads` feature, which is a continutation of a pre-1.0 API, can sometimes emit a [weird lifetime error](https://github.com/rust-lang/rust/issues/95527) without NLL. Second, actually seen in the standard library. In the `Extend` impl for `HashMap`, there is an implied bound of `K: 'a` that is available with NLL on but not without - this is utilized in the impl. As mentioned before, there are a large number of diagnostic differences. Most of them are better, but some are worse. None are serious or happen often enough to need to block this PR. The biggest change is the loss of error code for a number of lifetime errors in favor of more general "lifetime may not live long enough" error. While this may *seem* bad, the former error codes were just attempts to somewhat-arbitrarily bin together lifetime errors of the same type; however, on paper, they end up being roughly the same with roughly the same kinds of solutions. ## What isn't stabilized This PR does not completely remove the lexical region resolver. In the future, it may be possible to remove that (while still keeping HIR typeck) or to remove it together with HIR typeck. ## Tests Many test outputs get updated by this PR. However, there are number of tests specifically geared towards NLL under `src/test/ui/nll` ## History * On 2017-07-14, [tracking issue opened](https://github.com/rust-lang/rust/issues/43234) * On 2017-07-20, [initial empty MIR pass added](https://github.com/rust-lang/rust/pull/43271) * On 2017-08-29, [RFC opened](https://github.com/rust-lang/rfcs/pull/2094) * On 2017-11-16, [Integrate MIR type-checker with NLL](https://github.com/rust-lang/rust/pull/45825) * On 2017-12-20, [NLL feature complete](https://github.com/rust-lang/rust/pull/46862) * On 2018-07-07, [Don't run AST borrowck on mir mode](https://github.com/rust-lang/rust/pull/52083) * On 2018-07-27, [Add migrate mode](https://github.com/rust-lang/rust/pull/52681) * On 2019-04-22, [Enable migrate mode on 2015 edition](https://github.com/rust-lang/rust/pull/59114) * On 2019-08-26, [Don't downgrade errors on 2015 edition](https://github.com/rust-lang/rust/pull/64221) * On 2019-08-27, [Remove AST borrowck](https://github.com/rust-lang/rust/pull/64790)
2022-06-04Auto merge of #97604 - nnethercote:inline-bridge-Buffer-methods, r=eddybbors-0/+13
Inline `bridge::Buffer` methods. This fixes a performance regression caused by making `Buffer` non-generic in #97004. r? `@eddyb`
2022-06-03Fully stabilize NLLJack Huey-1/+0
2022-06-02Revert #96682.Nicholas Nethercote-3/+2
The change was "Show invisible delimiters (within comments) when pretty printing". It's useful to show these delimiters, but is a breaking change for some proc macros. Fixes #97608.
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`.