about summary refs log tree commit diff
path: root/compiler/rustc_session
AgeCommit message (Collapse)AuthorLines
2025-10-03Auto merge of #143613 - Enselic:panic-abort-uwtables, r=petrochenkovbors-1/+2
Fix backtraces with `-C panic=abort` on linux; emit unwind tables by default The linux backtrace unwinder relies on unwind tables to work properly, and generating and printing a backtrace is done by for example the default panic hook. Begin emitting unwind tables by default again with `-C panic=abort` (see history below) so that backtraces work. Closes https://github.com/rust-lang/rust/issues/81902 which is **regression-from-stable-to-stable** Closes https://github.com/rust-lang/rust/issues/94815 ### History Backtraces with `-C panic=abort` used to work in Rust 1.22 but broke in Rust 1.23, because in 1.23 we stopped emitting unwind tables with `-C panic=abort` (see https://github.com/rust-lang/rust/pull/45031 and https://github.com/rust-lang/rust/issues/81902#issuecomment-3046487084). In 1.45 a workaround in the form of `-C force-unwind-tables=yes` was added (see https://github.com/rust-lang/rust/pull/69984). `-C panic=abort` was added in [Rust 1.10](https://blog.rust-lang.org/2016/07/07/Rust-1.10/#what-s-in-1-10-stable) and the motivation was binary size and compile time. But given how confusing that behavior has turned out to be, it is better to make binary size optimization opt-in with `-C force-unwind-tables=no` rather than default since the current default breaks backtraces. Besides, if binary size is a primary concern, there are many other tricks that can be used that has a higher impact. # Release Note Entry Draft: ## Compatibility Notes * [Fix backtraces with `-C panic=abort` on Linux by generating unwind tables by default](https://github.com/rust-lang/rust/pull/143613). Build with `-C force-unwind-tables=no` to keep omitting unwind tables. try-job: aarch64-apple try-job: armhf-gnu try-job: aarch64-msvc-1
2025-10-02Fix backtraces with `-C panic=abort` on linux; emit unwind tables by defaultMartin Nordholts-1/+2
The linux backtrace unwinder relies on unwind tables to work properly, and generating and printing a backtrace is done by for example the default panic hook. Begin emitting unwind tables by default again with `-C panic=abort` (see history below) so that backtraces work. History ======= Backtraces with `-C panic=abort` used to work in Rust 1.22 but broke in Rust 1.23, because in 1.23 we stopped emitting unwind tables with `-C panic=abort` (see 24cc38e3b00). In 1.45 (see cda994633ee) a workaround in the form of `-C force-unwind-tables=yes` was added. `-C panic=abort` was added in [Rust 1.10](https://blog.rust-lang.org/2016/07/07/Rust-1.10/#what-s-in-1-10-stable) and the motivation was binary size and compile time. But given how confusing that behavior has turned out to be, it is better to make binary size optimization opt-in with `-C force-unwind-tables=no` rather than default since the current default breaks backtraces. Besides, if binary size is a primary concern, there are many other tricks that can be used that has a higher impact.
2025-09-29Auto merge of #146376 - durin42:dwo-specify-path, r=davidtwcobors-1/+13
debuginfo: add an unstable flag to write split DWARF to an explicit directory Bazel requires knowledge of outputs from actions at analysis time, including file or directory name. In order to work around the lack of predictable output name for dwo files, we group the dwo files in a subdirectory of --out-dir as a post-processing step before returning control to bazel. Unfortunately some debugging workflows rely on directly opening the dwo file rather than loading the merged dwp file, and our trick of moving the files breaks those users. We can't just hardlink the file or copy it, because with remote build execution we wouldn't end up with the un-moved file copied back to the developer's workstation. As a fix, we add this unstable flag that causes dwo files to be written to a build-system-controllable location, which then lets bazel hoover up the dwo files, but the objects also have the correct path for the dwo files. r? `@davidtwco`
2025-09-29Rollup merge of #147116 - workingjubilee:remove-tdl-abialign, r=ZalatharStuart Cook-5/+5
compiler: remove AbiAlign inside TargetDataLayout AbiAlign is a thin wrapper around Align, extant mostly because we used to track a separate quasi-notion of alignment that was never a real notion of alignment and removing all of it at once was too churny. This PR maintains AbiAlign usage in public API and most of the compiler, but direct access of these fields for TargetDataLayout is now in terms of Align only.
2025-09-28Rollup merge of #144197 - KMJ-007:type-tree, r=ZuseZ4Matthias Krüger-1/+4
TypeTree support in autodiff # TypeTrees for Autodiff ## What are TypeTrees? Memory layout descriptors for Enzyme. Tell Enzyme exactly how types are structured in memory so it can compute derivatives efficiently. ## Structure ```rust TypeTree(Vec<Type>) Type { offset: isize, // byte offset (-1 = everywhere) size: usize, // size in bytes kind: Kind, // Float, Integer, Pointer, etc. child: TypeTree // nested structure } ``` ## Example: `fn compute(x: &f32, data: &[f32]) -> f32` **Input 0: `x: &f32`** ```rust TypeTree(vec![Type { offset: -1, size: 8, kind: Pointer, child: TypeTree(vec![Type { offset: -1, size: 4, kind: Float, child: TypeTree::new() }]) }]) ``` **Input 1: `data: &[f32]`** ```rust TypeTree(vec![Type { offset: -1, size: 8, kind: Pointer, child: TypeTree(vec![Type { offset: -1, size: 4, kind: Float, // -1 = all elements child: TypeTree::new() }]) }]) ``` **Output: `f32`** ```rust TypeTree(vec![Type { offset: -1, size: 4, kind: Float, child: TypeTree::new() }]) ``` ## Why Needed? - Enzyme can't deduce complex type layouts from LLVM IR - Prevents slow memory pattern analysis - Enables correct derivative computation for nested structures - Tells Enzyme which bytes are differentiable vs metadata ## What Enzyme Does With This Information: Without TypeTrees (current state): ```llvm ; Enzyme sees generic LLVM IR: define float ``@distance(ptr*`` %p1, ptr* %p2) { ; Has to guess what these pointers point to ; Slow analysis of all memory operations ; May miss optimization opportunities } ``` With TypeTrees (our implementation): ```llvm define "enzyme_type"="{[]:Float@float}" float ``@distance(`` ptr "enzyme_type"="{[]:Pointer}" %p1, ptr "enzyme_type"="{[]:Pointer}" %p2 ) { ; Enzyme knows exact type layout ; Can generate efficient derivative code directly } ``` # TypeTrees - Offset and -1 Explained ## Type Structure ```rust Type { offset: isize, // WHERE this type starts size: usize, // HOW BIG this type is kind: Kind, // WHAT KIND of data (Float, Int, Pointer) child: TypeTree // WHAT'S INSIDE (for pointers/containers) } ``` ## Offset Values ### Regular Offset (0, 4, 8, etc.) **Specific byte position within a structure** ```rust struct Point { x: f32, // offset 0, size 4 y: f32, // offset 4, size 4 id: i32, // offset 8, size 4 } ``` TypeTree for `&Point` (internal representation): ```rust TypeTree(vec![ Type { offset: 0, size: 4, kind: Float }, // x at byte 0 Type { offset: 4, size: 4, kind: Float }, // y at byte 4 Type { offset: 8, size: 4, kind: Integer } // id at byte 8 ]) ``` Generates LLVM: ```llvm "enzyme_type"="{[]:Float@float}" ``` ### Offset -1 (Special: "Everywhere") **Means "this pattern repeats for ALL elements"** #### Example 1: Array `[f32; 100]` ```rust TypeTree(vec![Type { offset: -1, // ALL positions size: 4, // each f32 is 4 bytes kind: Float, // every element is float }]) ``` Instead of listing 100 separate Types with offsets `0,4,8,12...396` #### Example 2: Slice `&[i32]` ```rust // Pointer to slice data TypeTree(vec![Type { offset: -1, size: 8, kind: Pointer, child: TypeTree(vec![Type { offset: -1, // ALL slice elements size: 4, // each i32 is 4 bytes kind: Integer }]) }]) ``` #### Example 3: Mixed Structure ```rust struct Container { header: i64, // offset 0 data: [f32; 1000], // offset 8, but elements use -1 } ``` ```rust TypeTree(vec![ Type { offset: 0, size: 8, kind: Integer }, // header Type { offset: 8, size: 4000, kind: Pointer, child: TypeTree(vec![Type { offset: -1, size: 4, kind: Float // ALL array elements }]) } ]) ```
2025-09-27compiler: remove AbiAlign inside TargetDataLayoutJubilee Young-5/+5
This maintains AbiAlign usage in public API and most of the compiler, but direct access of these fields is now in terms of Align only.
2025-09-26debuginfo: add an unstable flag to write split DWARF to an explicit directoryAugie Fackler-1/+13
Bazel requires knowledge of outputs from actions at analysis time, including file or directory name. In order to work around the lack of predictable output name for dwo files, we group the dwo files in a subdirectory of --out-dir as a post-processing step before returning control to bazel. Unfortunately some debugging workflows rely on directly opening the dwo file rather than loading the merged dwp file, and our trick of moving the files breaks those users. We can't just hardlink the file or copy it, because with remote build execution we wouldn't end up with the un-moved file copied back to the developer's workstation. As a fix, we add this unstable flag that causes dwo files to be written to a build-system-controllable location, which then lets bazel hoover up the dwo files, but the objects also have the correct path for the dwo files.
2025-09-24Auto merge of #146338 - CrooseGit:dev/reucru01/AArch64-enable-GCS, ↵bors-1/+3
r=Urgau,davidtwco Extends AArch64 branch protection support to include GCS Extends existing support for AArch64 branch protection to include support for [Guarded Control Stacks](https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/arm-a-profile-architecture-2022#guarded-control-stack-gcs:~:text=Extraction%20or%20tracking.-,Guarded%20Control%20Stack%20(GCS),-With%20the%202022).
2025-09-21Explain tests and setting cfgsBen Kimock-0/+4
2025-09-21Add panic=immediate-abortBen Kimock-7/+23
2025-09-19generate list of all variants with `target_spec_enum`Deadbeef-2/+4
This helps us avoid the hardcoded lists elsewhere.
2025-09-19autodiff: Add basic TypeTree with NoTT flagKaran Janthe-1/+4
Signed-off-by: Karan Janthe <karanjanthe@gmail.com>
2025-09-18Set lto="fat" automatically when compiling with RUSTFLAGS="-Zautodiff=Enable".Haidong Zhang-0/+12
2025-09-17Adds AArch64 GCS supportReuben Cruise-1/+3
- Adds option to rustc config to enable GCS - Passes `guarded-control-stack` flag to llvm if enabled
2025-09-12Add --print target-spec-json-schemaNoratrieb-1/+4
This schema is helpful for people writing custom target spec JSON. It can provide autocomplete in the editor, and also serves as documentation when there are documentation comments on the structs, as `schemars` will put them in the schema.
2025-09-08fixup limit handling codeJana Dönszelmann-60/+2
2025-09-04Auto merge of #138736 - azhogin:azhogin/sanitizers-target-modificators, ↵bors-2/+69
r=rcvalle Sanitizers target modificators Depends on bool flag fix: https://github.com/rust-lang/rust/pull/138483. Some sanitizers need to be target modifiers, and some do not. For now, we should mark all sanitizers as target modifiers except for these: AddressSanitizer, LeakSanitizer For kCFI, the helper flag -Zsanitizer-cfi-normalize-integers should also be a target modifier. Many test errors was with sanizer flags inconsistent with std deps. Tests are fixed with `-C unsafe-allow-abi-mismatch`.
2025-09-02Revert introduction of `[workspace.dependencies]`.Nicholas Nethercote-3/+5
This was done in #145740 and #145947. It is causing problems for people using r-a on anything that uses the rustc-dev rustup package, e.g. Miri, clippy. This repository has lots of submodules and subtrees and various different projects are carved out of pieces of it. It seems like `[workspace.dependencies]` will just be more trouble than it's worth.
2025-08-29Rollup merge of #145947 - nnethercote:workspace-members-2, r=KobzolStuart Cook-3/+1
Add more to the `[workspace.dependencies]` section in the top-level `Cargo.toml` Following on from rust-lang/rust#145740. r? `@Kobzol`
2025-08-28Improve error messages around invalid literals in attribute argumentsJonathan Brouwer-10/+14
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-28Add `libc` to `[workspace.dependencies]`.Nicholas Nethercote-3/+1
2025-08-27Move `NativeLibKind` from `rustc_session` to `rustc_hir`Jonathan Brouwer-86/+5
2025-08-27Add `tracing` to `[workspace.dependencies]`.Nicholas Nethercote-1/+1
2025-08-27Add `bitflags` to `[workspace.dependencies]`.Nicholas Nethercote-1/+1
2025-08-24Support lints in early attribute parsingJana Dönszelmann-1/+16
2025-08-23Auto merge of #145567 - clubby789:cargo_update, r=clubby789bors-1/+3
Weekly `cargo update` (with libc pin) Supersedes rust-lang/rust#145516 Manually pins libc for `compiler` and `rustbook` (both of which use rustix), with fixmes to remove this later. ``` compiler & tools dependencies: Locking 28 packages to latest compatible versions Updating anyhow v1.0.98 -> v1.0.99 Updating bitflags v2.9.1 -> v2.9.2 Updating clap v4.5.43 -> v4.5.45 Updating clap_builder v4.5.43 -> v4.5.44 Updating clap_derive v4.5.41 -> v4.5.45 Updating curl v0.4.48 -> v0.4.49 Updating curl-sys v0.4.82+curl-8.14.1 -> v0.4.83+curl-8.15.0 Updating cxx v1.0.166 -> v1.0.168 Updating cxx-build v1.0.166 -> v1.0.168 Updating cxxbridge-cmd v1.0.166 -> v1.0.168 Updating cxxbridge-flags v1.0.166 -> v1.0.168 Updating cxxbridge-macro v1.0.166 -> v1.0.168 Updating glob v0.3.2 -> v0.3.3 Updating object v0.37.2 -> v0.37.3 Updating proc-macro2 v1.0.95 -> v1.0.101 Updating rayon v1.10.0 -> v1.11.0 Updating rayon-core v1.12.1 -> v1.13.0 Updating serde-untagged v0.1.7 -> v0.1.8 Updating socket2 v0.5.10 -> v0.6.0 Updating syn v2.0.104 -> v2.0.106 Updating thiserror v2.0.12 -> v2.0.15 Updating thiserror-impl v2.0.12 -> v2.0.15 Updating uuid v1.17.0 -> v1.18.0 Updating wasm-encoder v0.236.0 -> v0.236.1 Updating wasmparser v0.236.0 -> v0.236.1 Updating wast v236.0.0 -> v236.0.1 Updating wat v1.236.0 -> v1.236.1 note: pass `--verbose` to see 35 unchanged dependencies behind latest library dependencies: Locking 2 packages to latest compatible versions Updating libc v0.2.174 -> v0.2.175 Updating object v0.37.2 -> v0.37.3 note: pass `--verbose` to see 2 unchanged dependencies behind latest rustbook dependencies: Locking 13 packages to latest compatible versions Updating anyhow v1.0.98 -> v1.0.99 Updating bitflags v2.9.1 -> v2.9.2 Updating cc v1.2.32 -> v1.2.33 Updating clap v4.5.43 -> v4.5.45 Updating clap_builder v4.5.43 -> v4.5.44 Updating clap_complete v4.5.56 -> v4.5.57 Updating clap_derive v4.5.41 -> v4.5.45 Updating proc-macro2 v1.0.95 -> v1.0.101 Updating syn v2.0.104 -> v2.0.106 Updating terminal_size v0.4.2 -> v0.4.3 Updating thiserror v2.0.12 -> v2.0.15 Updating thiserror-impl v2.0.12 -> v2.0.15 ```
2025-08-22Migrate `BuiltinLintDiag::UnexpectedBuiltinCfg` to use `LintDiagnostic` directlyJosh Triplett-4/+17
2025-08-22Refactor lint buffering to avoid requiring a giant enumJosh Triplett-8/+8
Lint buffering currently relies on a giant enum `BuiltinLintDiag` containing all the lints that might potentially get buffered. In addition to being an unwieldy enum in a central crate, this also makes `rustc_lint_defs` a build bottleneck: it depends on various types from various crates (with a steady pressure to add more), and many crates depend on it. Having all of these variants in a separate crate also prevents detecting when a variant becomes unused, which we can do with a dedicated type defined and used in the same crate. Refactor this to use a dyn trait, to allow using `LintDiagnostic` types directly. This requires boxing, but all of this is already on the slow path (emitting an error). Because the existing `BuiltinLintDiag` requires some additional types in order to decorate some variants, which are only available later in `rustc_lint`, use an enum `DecorateDiagCompat` to handle both the `dyn LintDiagnostic` case and the `BuiltinLintDiag` case.
2025-08-21-Zsanitize and -Zsanitizer-cfi-normalize-integers flags are now target ↵Andrew Zhogin-2/+69
modifiers with custom consistency check function
2025-08-19mention lint group in default level lint noteKarol Zwolak-2/+19
2025-08-18cargo updategithub-actions-1/+3
compiler & tools dependencies: Locking 28 packages to latest compatible versions Updating anyhow v1.0.98 -> v1.0.99 Updating bitflags v2.9.1 -> v2.9.2 Updating clap v4.5.43 -> v4.5.45 Updating clap_builder v4.5.43 -> v4.5.44 Updating clap_derive v4.5.41 -> v4.5.45 Updating curl v0.4.48 -> v0.4.49 Updating curl-sys v0.4.82+curl-8.14.1 -> v0.4.83+curl-8.15.0 Updating cxx v1.0.166 -> v1.0.168 Updating cxx-build v1.0.166 -> v1.0.168 Updating cxxbridge-cmd v1.0.166 -> v1.0.168 Updating cxxbridge-flags v1.0.166 -> v1.0.168 Updating cxxbridge-macro v1.0.166 -> v1.0.168 Updating glob v0.3.2 -> v0.3.3 Updating object v0.37.2 -> v0.37.3 Updating proc-macro2 v1.0.95 -> v1.0.101 Updating rayon v1.10.0 -> v1.11.0 Updating rayon-core v1.12.1 -> v1.13.0 Updating serde-untagged v0.1.7 -> v0.1.8 Updating socket2 v0.5.10 -> v0.6.0 Updating syn v2.0.104 -> v2.0.106 Updating thiserror v2.0.12 -> v2.0.15 Updating thiserror-impl v2.0.12 -> v2.0.15 Updating uuid v1.17.0 -> v1.18.0 Updating wasm-encoder v0.236.0 -> v0.236.1 Updating wasmparser v0.236.0 -> v0.236.1 Updating wast v236.0.0 -> v236.0.1 Updating wat v1.236.0 -> v1.236.1 note: pass `--verbose` to see 35 unchanged dependencies behind latest library dependencies: Locking 2 packages to latest compatible versions Updating libc v0.2.174 -> v0.2.175 Updating object v0.37.2 -> v0.37.3 note: pass `--verbose` to see 2 unchanged dependencies behind latest rustbook dependencies: Locking 13 packages to latest compatible versions Updating anyhow v1.0.98 -> v1.0.99 Updating bitflags v2.9.1 -> v2.9.2 Updating cc v1.2.32 -> v1.2.33 Updating clap v4.5.43 -> v4.5.45 Updating clap_builder v4.5.43 -> v4.5.44 Updating clap_complete v4.5.56 -> v4.5.57 Updating clap_derive v4.5.41 -> v4.5.45 Updating proc-macro2 v1.0.95 -> v1.0.101 Updating syn v2.0.104 -> v2.0.106 Updating terminal_size v0.4.2 -> v0.4.3 Updating thiserror v2.0.12 -> v2.0.15 Updating thiserror-impl v2.0.12 -> v2.0.15
2025-08-17Add `-Zindirect-branch-cs-prefix` optionMiguel Ojeda-1/+13
This is intended to be used for Linux kernel RETPOLINE builds. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2025-08-17Add -Zindirect-branch-cs-prefix (from draft PR)Alice Ryhl-0/+2
2025-08-15Rollup merge of #145408 - Kobzol:deduplicate-search-paths, r=petrochenkovJakub Beránek-10/+21
Deduplicate -L search paths For each -L passed to the compiler, we eagerly scan the whole directory. If it has a lot of files, that results in a lot of allocations. So it's needless to do this if some -L paths are actually duplicated (which can happen e.g. in the situation in the linked issue). This PR both deduplicates the args, and also teaches rustdoc not to pass duplicated args to merged doctests. Fixes: https://github.com/rust-lang/rust/issues/145375
2025-08-15Rollup merge of #145005 - tardyp:lto_big_filesize, r=bjorn3Stuart Cook-2/+21
strip prefix of temporary file names when it exceeds filesystem name length limit When doing lto, rustc generates filenames that are concatenating many information. In the case of this testcase, it is concatenating crate name and rust file name, plus some hash, and the extension. In some other cases it will concatenate even more information reducing the maximum effective crate name to about 110 chars on linux filesystems where filename max length is 255 This commit is ensuring that the temporary file names are limited in size, while still reasonably ensuring the unicity (with hashing of the stripped part) Fix: rust-lang/rust#49914
2025-08-14Deduplicate `-L` paths passed to rustcJakub Beránek-10/+21
2025-08-13Fix parallel rustc not being reproducible due to unstable sorting of items.ywxt-0/+2
2025-08-10strip prefix of temporary file names when it exceeds filesystem name length ↵Pierre Tardy-2/+21
limit When doing lto, rustc generates filenames that are concatenating many information. In the case of this testcase, it is concatenating crate name and rust file name, plus some hash, and the extension. In some other cases it will concatenate even more information reducing the maximum effective crate name to about 110 chars on linux filesystems where filename max length is 255 This commit is ensuring that the temporary file names are limited in size, while still reasonabily ensuring the unicity (with hashing of the stripped part)
2025-08-06coverage: Remove all unstable support for MC/DC instrumentationZalathar-11/+2
2025-08-04coverage: Simplify access to debug/testing `-Zcoverage-options` flagsZalathar-5/+8
2025-08-04coverage: Remove `-Zcoverage-options=no-mir-spans`Zalathar-16/+1
This flag turned out to be less useful than anticipated, and interferes with work towards expansion support.
2025-07-28Auto merge of #144562 - matthiaskrgr:rollup-mlvn7qo, r=matthiaskrgrbors-2/+0
Rollup of 7 pull requests Successful merges: - rust-lang/rust#144072 (update `Atomic*::from_ptr` and `Atomic*::as_ptr` docs) - rust-lang/rust#144151 (`tests/ui/issues/`: The Issues Strike Back [1/N]) - rust-lang/rust#144300 (Clippy fixes for miropt-test-tools) - rust-lang/rust#144399 (Add a ratchet for moving all standard library tests to separate packages) - rust-lang/rust#144472 (str: Mark unstable `round_char_boundary` feature functions as const) - rust-lang/rust#144503 (Various refactors to the codegen coordinator code (part 3)) - rust-lang/rust#144530 (coverage: Infer `instances_used` from `pgo_func_name_var_map`) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-28Rollup merge of #144503 - bjorn3:lto_refactors3, r=petrochenkovMatthias Krüger-2/+0
Various refactors to the codegen coordinator code (part 3) Continuing from https://github.com/rust-lang/rust/pull/144062 this removes an option without any known users, uses the object crate in favor of LLVM for getting the LTO bitcode and improves the coordinator channel handling.
2025-07-28Auto merge of #144469 - Kivooeo:chains-cleanup, r=SparrowLiibors-9/+9
Some `let chains` clean-up Not sure if this kind of clean-up is welcoming because of size, but I decided to try out one r? compiler
2025-07-28use let chains in mir, resolve, targetKivooeo-9/+9
2025-07-26Remove support for -Zcombine-cgubjorn3-2/+0
Nobody seems to actually use this, while still adding some extra complexity to the already rather complex codegen coordinator code. It is also not supported by any backend other than the LLVM backend.
2025-07-25Allow pretty printing paths with `-Zself-profile-events=args`Jakub Beránek-0/+1
2025-07-24Rollup merge of #144218 - Noratrieb:target-spec-json-de-jank, r=fee1-deadLeón Orell Valerian Liehr-3/+3
Use serde for target spec json deserialize The previous manual parsing of `serde_json::Value` was a lot of complicated code and extremely error-prone. It was full of janky behavior like sometimes ignoring type errors, sometimes erroring for type errors, sometimes warning for type errors, and sometimes just ICEing for type errors (the icing on the top). Additionally, many of the error messages about allowed values were out of date because they were in a completely different place than the FromStr impls. Overall, the system caused confusion for users. I also found the old deserialization code annoying to read. Whenever a `key!` invocation was found, one had to first look for the right macro arm, and no go to definition could help. This PR replaces all this manual parsing with a 2-step process involving serde. First, the string is parsed into a `TargetSpecJson` struct. This struct is a 1:1 representation of the spec JSON. It already parses all the enums and is very simple to read and write. Then, the fields from this struct are copied into the actual `Target`. The reason for this two-step process instead of just serializing into a `Target` is because of a few reasons 1. There are a few transformations performed between the two formats 2. The default logic is implemented this way. Otherwise all the default field values would have to be spelled out again, which is suboptimal. With this logic, they fall out naturally, because everything in the json struct is an `Option`. Overall, the mapping is pretty simple, with the vast majority of fields just doing a 1:1 mapping that is captured by two macros. I have deliberately avoided making the macros generic to keep them simple. All the `FromStr` impls now have the error message right inside them, which increases the chance of it being up to date. Some "`from_str`" impls were turned into proper `FromStr` impls to support this. The new code is much less involved, delegating all the JSON parsing logic to serde, without any manual type matching. This change introduces a few breaking changes for consumers. While it is possible to use this format on stable, it is very much subject to change, so breaking changes are expected. The hope is also that because of the way stricter behavior, breaking changes are easier to deal with, as they come with clearer error messages. 1. Invalid types now always error, everywhere. Previously, they would sometimes error, and sometimes just be ignored (which meant the users JSON was still broken, just silently!) 2. This now makes use of `deny_unknown_fields` instead of just warning on unused fields, which was done previously. Serde doesn't make it easy to get such warning behavior, which was the primary reason that this now changed. But I think error behavior is very reasonable too. If someone has random stale fields in their JSON, it is likely because these fields did something at some point but no longer do, and the user likely wants to be informed of this so they can figure out what to do. This is also relevant for the future. If we remove a field but someone has it set, it probably makes sense for them to take a look whether they need this and should look for alternatives, or whether they can just delete it. Overall, the JSON is made more explicit. This is the only expected breakage, but there could also be small breakage from small mistakes. All targets roundtrip though, so it can't be anything too major. fixes rust-lang/rust#144153
2025-07-21Use serde for target spec json deserializeNoratrieb-3/+3
The previous manual parsing of `serde_json::Value` was a lot of complicated code and extremely error-prone. It was full of janky behavior like sometimes ignoring type errors, sometimes erroring for type errors, sometimes warning for type errors, and sometimes just ICEing for type errors (the icing on the top). Additionally, many of the error messages about allowed values were out of date because they were in a completely different place than the FromStr impls. Overall, the system caused confusion for users. I also found the old deserialization code annoying to read. Whenever a `key!` invocation was found, one had to first look for the right macro arm, and no go to definition could help. This PR replaces all this manual parsing with a 2-step process involving serde. First, the string is parsed into a `TargetSpecJson` struct. This struct is a 1:1 representation of the spec JSON. It already parses all the enums and is very simple to read and write. Then, the fields from this struct are copied into the actual `Target`. The reason for this two-step process instead of just serializing into a `Target` is because of a few reasons 1. There are a few transformations performed between the two formats 2. The default logic is implemented this way. Otherwise all the default field values would have to be spelled out again, which is suboptimal. With this logic, they fall out naturally, because everything in the json struct is an `Option`. Overall, the mapping is pretty simple, with the vast majority of fields just doing a 1:1 mapping that is captured by two macros. I have deliberately avoided making the macros generic to keep them simple. All the `FromStr` impls now have the error message right inside them, which increases the chance of it being up to date. Some "`from_str`" impls were turned into proper `FromStr` impls to support this. The new code is much less involved, delegating all the JSON parsing logic to serde, without any manual type matching. This change introduces a few breaking changes for consumers. While it is possible to use this format on stable, it is very much subject to change, so breaking changes are expected. The hope is also that because of the way stricter behavior, breaking changes are easier to deal with, as they come with clearer error messages. 1. Invalid types now always error, everywhere. Previously, they would sometimes error, and sometimes just be ignored (which meant the users JSON was still broken, just silently!) 2. This now makes use of `deny_unknown_fields` instead of just warning on unused fields, which was done previously. Serde doesn't make it easy to get such warning behavior, which was the primary reason that this now changed. But I think error behavior is very reasonable too. If someone has random stale fields in their JSON, it is likely because these fields did something at some point but no longer do, and the user likely wants to be informed of this so they can figure out what to do. This is also relevant for the future. If we remove a field but someone has it set, it probably makes sense for them to take a look whether they need this and should look for alternatives, or whether they can just delete it. Overall, the JSON is made more explicit. This is the only expected breakage, but there could also be small breakage from small mistakes. All targets roundtrip though, so it can't be anything too major.
2025-07-18add -Zoffload=Enable flag behind -Zunstable-options, to enable gpu (host) ↵Manuel Drehwald-1/+45
code generation