about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros
AgeCommit message (Collapse)AuthorLines
2025-05-27Remove `P::map`.Nicholas Nethercote-23/+18
It's barely used, and the places that use it are better if they don't.
2025-05-21Update UI testsMarcelo Domínguez-4/+3
2025-05-21Initial naive implementation using `Symbols` to represent autodiff modes ↵Marcelo Domínguez-8/+20
(`Forward`, `Reverse`) Since the mode is no longer part of `meta_item`, we must insert it manually (otherwise macro expansion with `#[rustc_autodiff]` won't work). This can be revised later if a more structured representation becomes necessary (using enums, annotated structs, etc). Some tests are currently failing. I'll address them next.
2025-05-21Disable autodiff bootstrappingMarcelo Domínguez-9/+1
2025-05-20Split `autodiff` into `autodiff_forward` and `autodiff_reverse`Marcelo Domínguez-14/+30
Pending fix. ``` error: cannot find a built-in macro with name `autodiff_forward` --> library\core\src\macros\mod.rs:1542:5 | 1542 | / pub macro autodiff_forward($item:item) { 1543 | | /* compiler built-in */ 1544 | | } | |_____^ error: cannot find a built-in macro with name `autodiff_reverse` --> library\core\src\macros\mod.rs:1549:5 | 1549 | / pub macro autodiff_reverse($item:item) { 1550 | | /* compiler built-in */ 1551 | | } | |_____^ error: could not compile `core` (lib) due to 2 previous errors ```
2025-05-19Rollup merge of #140874 - mejrs:rads, r=WaffleLapkinStuart Cook-1/+3
make `rustc_attr_parsing` less dominant in the rustc crate graph It has/had a glob re-export of `rustc_attr_data_structures`, which is a crate much lower in the graph, and a lot of crates were using it *just* (or *mostly*) for that re-export, while they can rely on `rustc_attr_data_structures` directly. Previous graph: ![graph_1](https://github.com/user-attachments/assets/f4a5f13c-4222-4903-b56d-28c83511fcbd) Graph with this PR: ![graph_2](https://github.com/user-attachments/assets/1e053d9c-75cc-402b-84df-86229c98277a) The first commit keeps the re-export, and just changes the dependency if possible. The second commit is the "breaking change" which removes the re-export, and "explicitly" adds the `rustc_attr_data_structures` dependency where needed. It also switches over some src/tools/*. The second commit is actually a lot more involved than I expected. Please let me know if it's a better idea to back it out and just keep the first commit.
2025-05-19Rollup merge of #140049 - haenoe:fix-autodiff-generics, r=ZuseZ4Stuart Cook-11/+62
fix autodiff macro on generic functions heloo there! This short PR allows applying the `autodiff` macro to generic functions like this one. It only touches the frontend part, since the `rustc_autodiff` macro can already handle generics. ```rust #[autodiff(d_square, Reverse, Duplicated, Active)] fn square<T: std::ops::Mul<Output = T> + Copy>(x: &T) -> T { *x * *x } ``` Thanks to Manuel for creating an issue on this. For more information on this see #140032 r? `@ZuseZ4` As always: thanks for any piece of feedback!! Fixes: #140032 Tracking issue for autodiff: https://github.com/rust-lang/rust/issues/124509
2025-05-18Remove rustc_attr_data_structures re-export from rustc_attr_parsingmejrs-1/+3
2025-05-18add `AsmOptions` with some named fieldsFolkert de Vries-19/+31
2025-05-18rename to get rid of the 'raw' conceptFolkert de Vries-63/+64
2025-05-18delay error for unsupported optionsFolkert de Vries-14/+2
2025-05-18attempt to have rustfmt use the new logicFolkert de Vries-17/+8
apparently it doesn't really use the asm parsing at present, so this may work?
2025-05-18a new parser generating the exact same error messagesFolkert de Vries-150/+226
Co-authored-by: Travis Cross <tc@traviscross.com>
2025-05-17extract operand parserFolkert de Vries-83/+93
2025-05-17determine later whether an explicit reg was usedFolkert de Vries-11/+9
2025-05-12update cfg(bootstrap)Pietro Albini-1/+0
2025-05-11feat: add generated parameters to generated functionHaeNoe-3/+52
- update pretty printing tests - only add generic parameters when function is actually generic (no empty turbofish)
2025-05-11feat: propagate generics to generated functionHaeNoe-8/+10
2025-05-10Remove `AstDeref`.Nicholas Nethercote-3/+3
It's a "utility trait to reduce boilerplate" implemented for `P` and `AstNodeWrapper`, but removing it gives a net reduction of twenty lines of code. It's also simpler to just implement `HasNodeId`/`HasAttrs`/`HasTokens` directly on types instead of via `AstDeref`. (I decided to make this change when doing some related refactoring and the error messages involving `AstDeref` and `HasAttrs` were hard to understand; removing it helped a lot.)
2025-05-06Remove duplicate impl of string unescapeMarijn Schouten-4/+7
2025-04-30Rollup merge of #140312 - nnethercote:DelimArgs-spacing, r=petrochenkovMatthias Krüger-2/+2
Improve pretty-printing of braces r? ````@petrochenkov````
2025-04-30Auto merge of #127516 - nnethercote:simplify-LazyAttrTokenStream, r=petrochenkovbors-0/+1
Simplify `LazyAttrTokenStream` `LazyAttrTokenStream` is an unpleasant type: `Lrc<Box<dyn ToAttrTokenStream>>`. Why does it look like that? - There are two `ToAttrTokenStream` impls, one for the lazy case, and one for the case where we already have an `AttrTokenStream`. - The lazy case (`LazyAttrTokenStreamImpl`) is implemented in `rustc_parse`, but `LazyAttrTokenStream` is defined in `rustc_ast`, which does not depend on `rustc_parse`. The use of the trait lets `rustc_ast` implicitly depend on `rustc_parse`. This explains the `dyn`. - `LazyAttrTokenStream` must have a `size_of` as small as possible, because it's used in many AST nodes. This explains the `Lrc<Box<_>>`, which keeps it to one word. (It's required `Lrc<dyn _>` would be a fat pointer.) This PR moves `LazyAttrTokenStreamImpl` (and a few other token stream things) from `rustc_parse` to `rustc_ast`. This lets us replace the `ToAttrTokenStream` trait with a two-variant enum and also remove the `Box`, changing `LazyAttrTokenStream` to `Lrc<LazyAttrTokenStreamInner>`. Plus it does a few cleanups. r? `@petrochenkov`
2025-04-30Simplify `LazyAttrTokenStream`.Nicholas Nethercote-0/+1
This commit does the following. - Changes it from `Lrc<Box<dyn ToAttrTokenStream>>` to `Lrc<LazyAttrTokenStreamInner>`. - Reworks `LazyAttrTokenStreamImpl` as `LazyAttrTokenStreamInner`, which is a two-variant enum. - Removes the `ToAttrTokenStream` trait and the two impls of it. The recursion limit must be increased in some crates otherwise rustdoc aborts.
2025-04-29Improve pretty-printing of braces.Nicholas Nethercote-2/+2
Most notably, the `FIXME` for suboptimal printing of `use` groups in `tests/ui/macros/stringify.rs` is fixed. And all other test output changes result in pretty printed output being closer to the original formatting in the source code.
2025-04-28Add or-patterns to pattern typesOli Scherer-1/+15
2025-04-28Directly generate TyPat instead of TyPatKindOli Scherer-9/+5
2025-04-28Pull ast pattern type parsing out into a separate functionOli Scherer-9/+19
2025-04-28Prevent pattern type macro invocations from having trailing tokensOli Scherer-1/+5
2025-04-23Make #![feature(let_chains)] bootstrap conditional in compiler/est31-1/+1
2025-04-22Rollup merge of #140104 - ↵Chris Denton-8/+6
Shourya742:2025-04-21-auto-diff-fails-on-impl-block, r=ZuseZ4 Fix auto diff failing on inherent impl blocks closes: #139557 r? ``@ZuseZ4``
2025-04-21support both trait and non-trail associated declarationbit-aloo-8/+6
2025-04-20remove a couple clonesMatthias Krüger-6/+4
2025-04-19Make `#[naked]` an unsafe attributeFolkert de Vries-2/+2
2025-04-18Rollup merge of #139615 - nnethercote:rm-name_or_empty, r=jdonszelmannMatthias Krüger-3/+2
Remove `name_or_empty` Another step towards #137978. r? ``@jdonszelmann``
2025-04-17Rollup merge of #139351 - EnzymeAD:autodiff-batching2, r=oli-obkMatthias Krüger-6/+17
Autodiff batching2 ~I will rebase it once my first PR landed.~ done. This autodiff batch mode is more similar to scalar autodiff, since it still only takes one shadow argument. However, that argument is supposed to be `width` times larger. r? `@oli-obk` Tracking: - https://github.com/rust-lang/rust/issues/124509
2025-04-16Move eager translation to a method on `Diag`Jake Goulding-7/+3
This will allow us to eagerly translate messages on a top-level diagnostic, such as a `LintDiagnostic`. As a bonus, we can remove the awkward closure passed into Subdiagnostic and make better use of `Into`.
2025-04-17Replace infallible `name_or_empty` methods with fallible `name` methods.Nicholas Nethercote-3/+2
I'm removing empty identifiers everywhere, because in practice they always mean "no identifier" rather than "empty identifier". (An empty identifier is impossible.) It's better to use `Option` to mean "no identifier" because you then can't forget about the "no identifier" possibility. Some specifics: - When testing an attribute for a single name, the commit uses the `has_name` method. - When testing an attribute for multiple names, the commit uses the new `has_any_name` method. - When using `match` on an attribute, the match arms now have `Some` on them. In the tests, we now avoid printing empty identifiers by not printing the identifier in the `error:` line at all, instead letting the carets point out the problem.
2025-04-16working dupv and dupvonly for fwd modeManuel Drehwald-6/+17
2025-04-14Auto merge of #139781 - jhpratt:rollup-qadsjvb, r=jhprattbors-41/+25
Rollup of 9 pull requests Successful merges: - #138336 (Improve `-Z crate-attr` diagnostics) - #139636 (Encode dep node edge count as u32 instead of usize) - #139666 (cleanup `mir_borrowck`) - #139695 (compiletest: consistently use `camino::{Utf8Path,Utf8PathBuf}` throughout) - #139699 (Proactively update coroutine drop shim's phase to account for later passes applied during shim query) - #139718 (enforce unsafe attributes in pre-2024 editions by default) - #139722 (Move some things to rustc_type_ir) - #139760 (UI tests: migrate remaining compile time `error-pattern`s to line annotations when possible) - #139776 (Switch attrs to `diagnostic::on_unimplemented`) r? `@ghost` `@rustbot` modify labels: rollup
2025-04-14Auto merge of #124141 - ↵bors-8/+3
nnethercote:rm-Nonterminal-and-TokenKind-Interpolated, r=petrochenkov Remove `Nonterminal` and `TokenKind::Interpolated` A third attempt at this; the first attempt was #96724 and the second was #114647. r? `@ghost`
2025-04-13Improve `-Z crate-attr` diagnosticsjyn-41/+25
- Show the `#![ ... ]` in the span (to make it clear that it should not be included in the CLI argument) - Show more detailed errors when the crate has valid token trees but invalid syntax. Previously, `crate-attr=feature(foo),feature(bar)` would just say "invalid crate attribute" and point at the comma. Now, it explicitly says that the comma was unexpected, which is useful when using `--error-format=short`. It also fixes the column to show the correct span. - Recover from parse errors. Previously we would abort immediately on syntax errors; now we go on to try and type-check the rest of the crate. The new diagnostic code also happens to be slightly shorter.
2025-04-10Rollup merge of #139510 - nnethercote:name-to-ident, r=fee1-deadMatthias Krüger-12/+12
Rename some `name` variables as `ident`. It bugs me when variables of type `Ident` are called `name`. It leads to silly things like `name.name`. `Ident` variables should be called `ident`, and `name` should be used for variables of type `Symbol`. This commit improves things by by doing `s/name/ident/` on a bunch of `Ident` variables. Not all of them, but a decent chunk. r? `@fee1-dead`
2025-04-10Rename some `name` variables as `ident`.Nicholas Nethercote-12/+12
It bugs me when variables of type `Ident` are called `name`. It leads to silly things like `name.name`. `Ident` variables should be called `ident`, and `name` should be used for variables of type `Symbol`. This commit improves things by by doing `s/name/ident/` on a bunch of `Ident` variables. Not all of them, but a decent chunk.
2025-04-08emit a better error message for using the macro incorrectlyManuel Drehwald-1/+1
2025-04-06refactor: simplify function-info gatheringHaeNoe-41/+26
2025-04-06fix usage of `autodiff` macro with inner functionsHaeNoe-32/+76
- fix errors caused by the move of `ast::Item::ident` (see #138740) - move the logic of getting `sig`, `vis`, and `ident` from two seperate `match` statements into one (less repetition especially with the nested `match`)
2025-04-05Rollup merge of #137880 - EnzymeAD:autodiff-batching, r=oli-obkStuart Cook-126/+222
Autodiff batching Enzyme supports batching, which is especially known from the ML side when training neural networks. There we would normally have a training loop, where in each iteration we would pass in some data (e.g. an image), and a target vector. Based on how close we are with our prediction we compute our loss, and then use backpropagation to compute the gradients and update our weights. That's quite inefficient, so what you normally do is passing in a batch of 8/16/.. images and targets, and compute the gradients for those all at once, allowing better optimizations. Enzyme supports batching in two ways, the first one (which I implemented here) just accepts a Batch size, and then each Dual/Duplicated argument has not one, but N shadow arguments. So instead of ```rs for i in 0..100 { df(x[i], y[i], 1234); } ``` You can now do ```rs for i in 0..100.step_by(4) { df(x[i+0],x[i+1],x[i+2],x[i+3], y[i+0], y[i+1], y[i+2], y[i+3], 1234); } ``` which will give the same results, but allows better compiler optimizations. See the testcase for details. There is a second variant, where we can mark certain arguments and instead of having to pass in N shadow arguments, Enzyme assumes that the argument is N times longer. I.e. instead of accepting 4 slices with 12 floats each, we would accept one slice with 48 floats. I'll implement this over the next days. I will also add more tests for both modes. For any one preferring some more interactive explanation, here's a video of Tim's llvm dev talk, where he presents his work. https://www.youtube.com/watch?v=edvaLAL5RqU I'll also add some other docs to the dev guide and user docs in another PR. r? ghost Tracking: - https://github.com/rust-lang/rust/issues/124509 - https://github.com/rust-lang/rust/issues/135283
2025-04-03add the autodiff batch mode frontendManuel Drehwald-126/+222
2025-04-02Remove `recursion_limit` increases.Nicholas Nethercote-1/+0
These are no longer needed now that `Nonterminal` is gone.
2025-04-02Remove `TokenStream::flattened` and `InvisibleOrigin::FlattenToken`.Nicholas Nethercote-7/+3
They are no longer needed. This does slightly worsen the error message for a single test, but that test contains code that is so badly broken that I'm not worried about it.