about summary refs log tree commit diff
path: root/compiler/rustc_expand/src
AgeCommit message (Collapse)AuthorLines
2022-10-11fix #102878Takayuki Maeda-8/+11
2022-10-05Remove `TokenStreamBuilder`.Nicholas Nethercote-43/+42
`TokenStreamBuilder` exists to concatenate multiple `TokenStream`s together. This commit removes it, and moves the concatenation functionality directly into `TokenStream`, via two new methods `push_tree` and `push_stream`. This makes things both simpler and faster. `push_tree` is particularly important. `TokenStreamBuilder` only had a single `push` method, which pushed a stream. But in practice most of the time we push a single token tree rather than a stream, and `push_tree` avoids the need to build a token stream with a single entry (which requires two allocations, one for the `Lrc` and one for the `Vec`). The main `push_tree` use arises from a change to one of the `ToInternal` impls in `proc_macro_server.rs`. It now returns a `SmallVec` instead of a `TokenStream`. This return value is then iterated over by `concat_trees`, which does `push_tree` on each element. Furthermore, the use of `SmallVec` avoids more allocations, because there is always only one or two token trees. Note: the removed `TokenStreamBuilder::push` method had some code to deal with a quadratic blowup case from #57735. This commit removes the code. I tried and failed to reproduce the blowup from that PR, before and after this change. Various other changes have happened to `TokenStreamBuilder` in the meantime, so I suspect the original problem is no longer relevant, though I don't have proof of this. Generally speaking, repeatedly extending a `Vec` without pre-determining its capacity is *not* quadratic. It's also incredibly common, within rustc and many other Rust programs, so if there were performance problems there you'd think it would show up in other places, too.
2022-10-05Rearrange `to_internal`.Nicholas Nethercote-41/+40
`TokenTree::Punct` is handled outside the `match`. This commits moves it inside the `match`, avoiding the need for the `return`s and making it easier to read.
2022-10-04Improve spans when splitting multi-char operator tokens for proc macros.Nicholas Nethercote-2/+14
2022-10-03Clarify operator splitting.Nicholas Nethercote-2/+6
I found this code hard to read.
2022-09-27Rewrite and refactor format_args!() builtin macro.Mara Bos-0/+4
2022-09-26remove cfg(bootstrap)Pietro Albini-1/+0
2022-09-21FIX - adopt new Diagnostic naming in newly migrated modulesJhonny Bill Mena-1/+1
FIX - ambiguous Diagnostic link in docs UPDATE - rename diagnostic_items to IntoDiagnostic and AddToDiagnostic [Gardening] FIX - formatting via `x fmt` FIX - rebase conflicts. NOTE: Confirm wheather or not we want to handle TargetDataLayoutErrorsWrapper this way DELETE - unneeded allow attributes in Handler method FIX - broken test FIX - Rebase conflict UPDATE - rename residual _SessionDiagnostic and fix LintDiag link
2022-09-21UPDATE - rename SessionSubdiagnostic macro to SubdiagnosticJhonny Bill Mena-1/+1
Also renames: - sym::AddSubdiagnostic to sym:: Subdiagnostic - rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
2022-09-21UPDATE - rename DiagnosticHandler macro to DiagnosticJhonny Bill Mena-7/+7
2022-09-21UPDATE - rename DiagnosticHandler trait to IntoDiagnosticJhonny Bill Mena-10/+10
2022-09-21UPDATE - move SessionDiagnostic from rustc_session to rustc_errorsJhonny Bill Mena-2/+4
2022-09-20Add the `#[derive_const]` attributeDeadbeef-7/+11
2022-09-15Only enable the let_else feature on bootstrapest31-1/+1
On later stages, the feature is already stable. Result of running: rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-09-14make `mk_attr_id` part of `ParseSess`SparrowLii-2/+8
2022-09-13Rollup merge of #101602 - nnethercote:AttrTokenStream, r=petrochenkovDylan DPC-29/+29
Streamline `AttrAnnotatedTokenStream` r? ```@petrochenkov```
2022-09-09Rename `{Create,Lazy}TokenStream` as `{To,Lazy}AttrTokenStream`.Nicholas Nethercote-7/+7
`To` is better than `Create` for indicating that this is a non-consuming conversion, rather than creating something out of nothing. And the addition of `Attr` is because the current names makes them sound like they relate to `TokenStream`, but really they relate to `AttrTokenStream`.
2022-09-09Change return type of `Attribute::tokens`.Nicholas Nethercote-1/+1
The `AttrTokenStream` is always immediately turned into a `TokenStream`.
2022-09-09Rename `AttrAnnotatedToken{Stream,Tree}`.Nicholas Nethercote-21/+21
These two type names are long and have long matching prefixes. I find them hard to read, especially in combinations like `AttrAnnotatedTokenStream::new(vec![AttrAnnotatedTokenTree::Token(..)])`. This commit renames them as `AttrToken{Stream,Tree}`.
2022-09-09Move `Spacing` out of `AttrAnnotatedTokenStream`.Nicholas Nethercote-11/+11
And into `AttrAnnotatedTokenTree::Token`. PR #99887 did the same thing for `TokenStream`.
2022-09-07ssa: implement `#[collapse_debuginfo]`David Wood-16/+23
Debuginfo line information for macro invocations are collapsed by default - line information are replaced by the line of the outermost expansion site. Using `-Zdebug-macros` disables this behaviour. When the `collapse_debuginfo` feature is enabled, the default behaviour is reversed so that debuginfo is not collapsed by default. In addition, the `#[collapse_debuginfo]` attribute is available and can be applied to macro definitions which will then have their line information collapsed. Signed-off-by: David Wood <david.wood@huawei.com>
2022-09-02Refactor and re-use BindingAnnotationCameron Steffen-6/+4
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-1/+3
by module
2022-09-01Auto merge of #100707 - dzvon:fix-typo, r=davidtwcobors-2/+2
Fix a bunch of typo This PR will fix some typos detected by [typos]. I only picked the ones I was sure were spelling errors to fix, mostly in the comments. [typos]: https://github.com/crate-ci/typos
2022-09-01Auto merge of #100210 - mystor:proc_macro_diag_struct, r=eddybbors-36/+17
proc_macro/bridge: send diagnostics over the bridge as a struct 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`. r? `@eddyb`
2022-08-31Fix ci checksDezhi Wu-1/+1
2022-08-31Fix a bunch of typoDezhi Wu-3/+3
This PR will fix some typos detected by [typos]. I only picked the ones I was sure were spelling errors to fix, mostly in the comments. [typos]: https://github.com/crate-ci/typos
2022-08-29Revert let_chains stabilizationNilstrieb-0/+1
This reverts commit 326646074940222d602f3683d0559088690830f4. This is the revert against master, the beta revert was already done in #100538.
2022-08-23Remove the symbol from `ast::LitKind::Err`.Nicholas Nethercote-1/+1
Because it's never used meaningfully.
2022-08-22Use `AttrVec` in more places.Nicholas Nethercote-21/+23
In some places we use `Vec<Attribute>` and some places we use `ThinVec<Attribute>` (a.k.a. `AttrVec`). This results in various points where we have to convert between `Vec` and `ThinVec`. This commit changes the places that use `Vec<Attribute>` to use `AttrVec`. A lot of this is mechanical and boring, but there are some interesting parts: - It adds a few new methods to `ThinVec`. - It implements `MapInPlace` for `ThinVec`, and introduces a macro to avoid the repetition of this trait for `Vec`, `SmallVec`, and `ThinVec`. Overall, it makes the code a little nicer, and has little effect on performance. But it is a precursor to removing `rustc_data_structures::thin_vec::ThinVec` and replacing it with `thin_vec::ThinVec`, which is implemented more efficiently.
2022-08-21Replace #[lint/warning/error] with #[diag]Xiretza-6/+6
2022-08-20Auto merge of #100564 - nnethercote:box-ast-MacCall, r=spastorinobors-15/+15
Box the `MacCall` in various types. r? `@spastorino`
2022-08-18Rollup merge of #100669 - nnethercote:attribute-cleanups, r=spastorinoMatthias Krüger-2/+1
Attribute cleanups r? `@ghost`
2022-08-18Rollup merge of #100651 - nidnogg:diagnostics_migration_expand_transcribe, ↵Matthias Krüger-24/+59
r=davidtwco Migrations for rustc_expand transcribe.rs This PR includes some migrations to the new diagnostics API for the `rustc_expand` module. r? ```@davidtwco```
2022-08-17Hotfix for duplicated slug name on VarStillRepeating structnidnogg-1/+1
2022-08-17Moved structs to rustc_expand::errors, added several more migrations, fixed ↵nidnogg-3/+1
slug name
2022-08-17Moved structs to rustc_expand::errors, added several more migrations, fixed ↵nidnogg-33/+58
slug name
2022-08-17Remove `attrs` arg from `typaram` and `mk_ty_param`.Nicholas Nethercote-2/+1
Because it's always empty.
2022-08-16Previous commit under x.py fmtnidnogg-1/+1
2022-08-17Box the `MacCall` in various types.Nicholas Nethercote-15/+15
2022-08-16Migrated more diagnostics under transcribe.rsnidnogg-9/+17
2022-08-16Added first migration for repeated expressions without syntax varsnidnogg-5/+9
2022-08-16Rename some things related to literals.Nicholas Nethercote-7/+13
- Rename `ast::Lit::token` as `ast::Lit::token_lit`, because its type is `token::Lit`, which is not a token. (This has been confusing me for a long time.) reasonable because we have an `ast::token::Lit` inside an `ast::Lit`. - Rename `LitKind::{from,to}_lit_token` as `LitKind::{from,to}_token_lit`, to match the above change and `token::Lit`.
2022-08-16Make `ExtCtxt::expr_lit` non-`pub`.Nicholas Nethercote-5/+17
By using `expr_str` more and adding `expr_{char,byte_str}`.
2022-08-12Adjust cfgsMark Rousskov-1/+0
2022-08-10Use &mut Diagnostic instead of &mut DiagnosticBuilder unless neededMichael Goulet-6/+2
2022-08-09Rollup merge of #96478 - WaffleLapkin:rustc_default_body_unstable, r=Aaron1011Dylan DPC-1/+12
Implement `#[rustc_default_body_unstable]` This PR implements a new stability attribute — `#[rustc_default_body_unstable]`. `#[rustc_default_body_unstable]` controls the stability of default bodies in traits. For example: ```rust pub trait Trait { #[rustc_default_body_unstable(feature = "feat", isssue = "none")] fn item() {} } ``` In order to implement `Trait` user needs to either - implement `item` (even though it has a default implementation) - enable `#![feature(feat)]` This is useful in conjunction with [`#[rustc_must_implement_one_of]`](https://github.com/rust-lang/rust/pull/92164), we may want to relax requirements for a trait, for example allowing implementing either of `PartialEq::{eq, ne}`, but do so in a safe way — making implementation of only `PartialEq::ne` unstable. r? `@Aaron1011` cc `@nrc` (iirc you were interested in this wrt `read_buf`), `@danielhenrymantilla` (you were interested in the related `#[rustc_must_implement_one_of]`) P.S. This is my first time working with stability attributes, so I'm not sure if I did everything right 😅
2022-08-06proc_macro/bridge: send diagnostics over the bridge as a structNika Layzell-36/+17
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-30Auto merge of #99887 - nnethercote:rm-TreeAndSpacing, r=petrochenkovbors-100/+89
Remove `TreeAndSpacing`. A `TokenStream` contains a `Lrc<Vec<(TokenTree, Spacing)>>`. But this is not quite right. `Spacing` makes sense for `TokenTree::Token`, but does not make sense for `TokenTree::Delimited`, because a `TokenTree::Delimited` cannot be joined with another `TokenTree`. This commit fixes this problem, by adding `Spacing` to `TokenTree::Token`, changing `TokenStream` to contain a `Lrc<Vec<TokenTree>>`, and removing the `TreeAndSpacing` typedef. The commit removes these two impls: - `impl From<TokenTree> for TokenStream` - `impl From<TokenTree> for TreeAndSpacing` These were useful, but also resulted in code with many `.into()` calls that was hard to read, particularly for anyone not highly familiar with the relevant types. This commit makes some other changes to compensate: - `TokenTree::token()` becomes `TokenTree::token_{alone,joint}()`. - `TokenStream::token_{alone,joint}()` are added. - `TokenStream::delimited` is added. This results in things like this: ```rust TokenTree::token(token::Semi, stmt.span).into() ``` changing to this: ```rust TokenStream::token_alone(token::Semi, stmt.span) ``` This makes the type of the result, and its spacing, clearer. These changes also simplifies `Cursor` and `CursorRef`, because they no longer need to distinguish between `next` and `next_with_spacing`. r? `@petrochenkov`
2022-07-29proc_macro: use crossbeam channels for the proc_macro cross-thread bridgeNika Layzell-7/+37
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.