summary refs log tree commit diff
path: root/compiler/rustc_metadata/src
AgeCommit message (Collapse)AuthorLines
2024-01-30Remove the lifetime from `DiagnosticArgValue`.Nicholas Nethercote-1/+1
Because it's almost always static. This makes `impl IntoDiagnosticArg for DiagnosticArgValue` trivial, which is nice. There are a few diagnostics constructed in `compiler/rustc_mir_build/src/check_unsafety.rs` and `compiler/rustc_mir_transform/src/errors.rs` that now need symbols converted to `String` with `to_string` instead of `&str` with `as_str`, but that' no big deal, and worth it for the simplifications elsewhere.
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-14/+14
Error codes are integers, but `String` is used everywhere to represent them. Gross! This commit introduces `ErrCode`, an integral newtype for error codes, replacing `String`. It also introduces a constant for every error code, e.g. `E0123`, and removes the `error_code!` macro. The constants are imported wherever used with `use rustc_errors::codes::*`. With the old code, we have three different ways to specify an error code at a use point: ``` error_code!(E0123) // macro call struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call \#[diag(name, code = "E0123")] // string struct Diag; ``` With the new code, they all use the `E0123` constant. ``` E0123 // constant struct_span_code_err!(dcx, span, E0123, "msg"); // constant \#[diag(name, code = E0123)] // constant struct Diag; ``` The commit also changes the structure of the error code definitions: - `rustc_error_codes` now just defines a higher-order macro listing the used error codes and nothing else. - Because that's now the only thing in the `rustc_error_codes` crate, I moved it into the `lib.rs` file and removed the `error_codes.rs` file. - `rustc_errors` uses that macro to define everything, e.g. the error code constants and the `DIAGNOSTIC_TABLES`. This is in its new `codes.rs` file.
2024-01-25Remove unused featuresclubby789-2/+0
2024-01-23Remove track_errors entirelyOli Scherer-2/+9
2024-01-18Rollup merge of #119869 - oli-obk:track_errors2, r=matthewjasperMatthias Krüger-4/+4
replace `track_errors` usages with bubbling up `ErrorGuaranteed` more of the same as https://github.com/rust-lang/rust/pull/117449 (removing `track_errors`)
2024-01-17Improved collapse_debuginfo attribute, added command-line flag (no|external|yes)Andrew Zhogin-0/+1
2024-01-17Make crate_inherent_impls fallible and stop using `track_errors` for itOli Scherer-4/+4
2024-01-13Auto merge of #119088 - George-lewis:glewis/suggest-upgrading-compiler, ↵bors-10/+5
r=Nilstrieb Suggest Upgrading Compiler for Gated Features This PR addresses #117318 I have a few questions: 1. Do we want to specify the current version and release date of the compiler? I have added this in via environment variables, which I found in the code for the rustc cli where it handles the `--version` flag a. How can I handle the changing message in the tests? 3. Do we want to only show this message when the compiler is old? a. How can we determine when the compiler is old? I'll wait until we figure out the message to bless the tests
2024-01-13Add check for ui_testing via promoting parameters from `ParseSess` to `Session`George-lewis-10/+5
2024-01-13Rollup merge of #119587 - beepster4096:system_varargs, r=petrochenkovMatthias Krüger-2/+14
Varargs support for system ABI This PR allows functions with the `system` ABI to be variadic (under the `extended_varargs_abi_support` feature tracked in #100189). On x86 windows, the `system` ABI is equivalent to `C` for variadic functions. On other platforms, `system` is already equivalent to `C`. Fixes #110505
2024-01-12allow system abi to be variadicbeepster4096-2/+14
2024-01-06Auto merge of #119478 - bjorn3:no_serialize_specialization, r=wesleywiserbors-129/+113
Avoid specialization in the metadata serialization code With the exception of a perf-only specialization for byte slices and byte vectors. This uses the same trick of introducing a new trait and having the Encodable and Decodable derives add a bound to it as used for TyEncoder/TyDecoder. The new code is clearer about which encoder/decoder uses which impl and it reduces the dependency of rustc on specialization, making it easier to remove support for specialization entirely or turn it into a construct that is only allowed for perf optimizations if we decide to do this.
2024-01-05Auto merge of #119634 - matthiaskrgr:rollup-v2xt7et, r=matthiaskrgrbors-58/+58
Rollup of 8 pull requests Successful merges: - #119151 (Hide foreign `#[doc(hidden)]` paths in import suggestions) - #119350 (Imply outlives-bounds on lazy type aliases) - #119354 (Make `negative_bounds` internal & fix some of its issues) - #119506 (Use `resolutions(()).effective_visiblities` to avoid cycle errors in `report_object_error`) - #119554 (Fix scoping for let chains in match guards) - #119563 (Check yield terminator's resume type in borrowck) - #119589 (cstore: Remove unnecessary locking from `CrateMetadata`) - #119622 (never patterns: Document behavior of never patterns with macros-by-example) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-05Rollup merge of #119589 - petrochenkov:cdatalock, r=Mark-SimulacrumMatthias Krüger-58/+58
cstore: Remove unnecessary locking from `CrateMetadata` Locks and atomics in `CrateMetadata` fields were necessary before https://github.com/rust-lang/rust/pull/107765 when `CStore` was cloneable, but now they are not necessary and can be removed after restructuring the code a bit to please borrow checker. All remaining locked fields in `CrateMetadata` are lazily populated caches.
2024-01-05Auto merge of #119192 - michaelwoerister:mcp533-push, r=cjgillotbors-13/+8
Replace a number of FxHashMaps/Sets with stable-iteration-order alternatives This PR replaces almost all of the remaining `FxHashMap`s in query results with either `FxIndexMap` or `UnordMap`. The only case that is missing is the `EffectiveVisibilities` struct which turned out to not be straightforward to transform. Once that is done too, we can remove the `HashStable` implementation from `HashMap`. The first commit adds the `StableCompare` trait which is a companion trait to `StableOrd`. Some types like `Symbol` can be compared in a cross-session stable way, but their `Ord` implementation is not stable. In such cases, a `StableCompare` implementation can be provided to offer a lightweight way for stable sorting. The more heavyweight option is to sort via `ToStableHashKey`, but then sorting needs to have access to a stable hashing context and `ToStableHashKey` can also be expensive as in the case of `Symbol` where it has to allocate a `String`. The rest of the commits are rather mechanical and don't overlap, so they are best reviewed individually. Part of [MCP 533](https://github.com/rust-lang/compiler-team/issues/533).
2024-01-05Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-errorsMichael Goulet-11/+11
Cleanup error handlers: round 5 More rustc_errors cleanups. A sequel to https://github.com/rust-lang/rust/pull/119171. r? ````@compiler-errors````
2024-01-04cstore: Remove unnecessary locking from `CrateMetadata`Vadim Petrochenkov-58/+58
2024-01-04Make iteration order of collect_return_position_impl_trait_in_trait_tys ↵Michael Woerister-2/+2
query stable
2024-01-04Make iteration order of crate_inherent_impls query result stable.Michael Woerister-9/+3
2024-01-04Replace a number of FxHashMaps/Sets with stable-iteration-order alternatives.Michael Woerister-2/+3
2024-01-03Rollup merge of #119510 - saethlin:fatal-io-errors, r=WaffleLapkin,NilstriebLeón Orell Valerian Liehr-2/+2
Report I/O errors from rmeta encoding with emit_fatal https://github.com/rust-lang/rust/issues/119456 reminded me that I never did systematic testing to provoke the out-of-disk ICEs so I grepped through a recent crater run (https://github.com/rust-lang/rust/pull/119440#issuecomment-1873393963) for more out-of-disk ICEs on current master and yep there's 2 in there. So I finally cooked up a way to provoke for these crashes. I wrote a little `cdylib` crate that has a `#[no_mangle] pub extern "C" fn write` which occasionally reports `ENOSPC`, and prints a backtrace when it does. <details><summary><strong>code for the dylib</strong></summary> <p> ```rust // cargo add libc rand backtrace use rand::Rng; #[no_mangle] pub extern "C" fn write( fd: libc::c_int, buf: *const libc::c_void, count: libc::size_t, ) -> libc::ssize_t { if fd > 2 && rand::thread_rng().gen::<u8>() == 0 { let mut count = 0; backtrace::trace(|frame| { backtrace::resolve_frame(frame, |symbol| { if let Some(name) = symbol.name() { if count > 3 { eprintln!("{}", name); } } count += 1; }); true }); unsafe { *libc::__errno_location() = libc::ENOSPC; } return -1; } else { unsafe { let res = libc::syscall(libc::SYS_write, fd as usize, buf as usize, count as usize) as isize; if res < 0 { *libc::__errno_location() = -res as i32; -1 } else { res } } } } ``` </p> </details> Then `LD_PRELOAD` that dylib and repeatedly build a big project until it ICEs, such as with this: ```bash while true; do cargo clean LD_PRELOAD=/home/ben/evil/target/release/libevil.so cargo +stage1 check 2> errors if grep "thread 'rustc' panicked" errors; then break fi done ``` My "big project" for testing was an otherwise-empty project with `cargo add axum`. Before this PR, the above procedure finds a crash in between 1 and 15 minutes. With this PR, I have not found a crash in 30 minutes, and I'll be leaving this to run overnight (starting now). (A night has now passed, no crashes were found) I believe the problem is that even though since https://github.com/rust-lang/rust/pull/117301 we correctly check `FileEncoder` for errors on all paths, we use `emit_err`, so there is a window of time between the call to `emit_err` and the full error reporting where rustc believes it has emitted a valid rmeta file and will permit Cargo to launch a build for a dependent crate. Changing these calls to `emit_fatal` closes that window. I think there are a number of other cases where `emit_err` has been used instead of the more-correct `emit_fatal` such as https://github.com/rust-lang/rust/blob/e51e98dde6a60637b6a71b8105245b629ac3fe77/compiler/rustc_codegen_ssa/src/back/write.rs#L542 but unlike rmeta encoding I am not aware of those cases of those causing problems. r? ``@WaffleLapkin``
2024-01-03Rename some `Diagnostic` setters.Nicholas Nethercote-11/+11
`Diagnostic` has 40 methods that return `&mut Self` and could be considered setters. Four of them have a `set_` prefix. This doesn't seem necessary for a type that implements the builder pattern. This commit removes the `set_` prefixes on those four methods.
2024-01-02Report I/O errors with emit_fatal not emit_errBen Kimock-2/+2
2023-12-31Avoid specialization for AttrId deserializationbjorn3-6/+3
2023-12-31Remove almost all uses of specialization from the metadata encoding codebjorn3-106/+93
2023-12-31Avoid specialization for the Span Encodable and Decodable implsbjorn3-20/+20
2023-12-29Shrink span encoding furtherMark Rousskov-47/+130
Spans are now stored in a more compact form which cuts down on at least 1 byte per span (indirect/direct encoding) and at most 3 bytes per span (indirect/direct encoding, context byte, length byte). As a result, libcore metadata shrinks by 1.5MB.
2023-12-29Auto merge of #119259 - cjgillot:single-crate-id, r=Mark-Simulacrumbors-1/+3
Only store StableCrateId once in DefPathTable. https://github.com/rust-lang/rust/pull/119238 made me think of this. cc `@Mark-Simulacrum`
2023-12-28Movability doesn't need to be a query anymoreMichael Goulet-11/+1
2023-12-28Remove movability from TyKind::CoroutineMichael Goulet-0/+10
2023-12-27Auto merge of #119302 - Mark-Simulacrum:relative-spans, r=WaffleLapkinbors-3/+24
Support encoding spans with relative offsets The relative offset is often smaller than the absolute offset, and with the LEB128 encoding, this ends up cutting the overall metadata size considerably (~1.5 megabytes on libcore). We can support both relative and absolute encodings essentially for free since we already take a full byte to differentiate between direct and indirect encodings (so an extra variant is quite cheap).
2023-12-27Support relative offsets when encoding spansMark Rousskov-3/+24
The relative offset is often smaller than the absolute offset, and with the LEB128 encoding, this ends up cutting the overall metadata size considerably (~1.5 megabytes on libcore). We can support both relative and absolute encodings essentially for free since we already take a full byte to differentiate between direct and indirect encodings (so an extra variant is quite cheap).
2023-12-26Auto merge of #119258 - compiler-errors:closure-kind, r=eholkbors-1/+2
Make closures carry their own ClosureKind Right now, we use the "`movability`" field of `hir::Closure` to distinguish a closure and a coroutine. This is paired together with the `CoroutineKind`, which is located not in the `hir::Closure`, but the `hir::Body`. This is strange and redundant. This PR introduces `ClosureKind` with two variants -- `Closure` and `Coroutine`, which is put into `hir::Closure`. The `CoroutineKind` is thus removed from `hir::Body`, and `Option<Movability>` no longer needs to be a stand-in for "is this a closure or a coroutine". r? eholk
2023-12-26Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, ↵bors-94/+104
r=compiler-errors Remove `DiagCtxt` API duplication `DiagCtxt` defines the internal API for creating and emitting diagnostics: methods like `struct_err`, `struct_span_warn`, `note`, `create_fatal`, `emit_bug`. There are over 50 methods. Some of these methods are then duplicated across several other types: `Session`, `ParseSess`, `Parser`, `ExtCtxt`, and `MirBorrowckCtxt`. `Session` duplicates the most, though half the ones it does are unused. Each duplicated method just calls forward to the corresponding method in `DiagCtxt`. So this duplication exists to (in the best case) shorten chains like `ecx.tcx.sess.parse_sess.dcx.emit_err()` to `ecx.emit_err()`. This API duplication is ugly and has been bugging me for a while. And it's inconsistent: there's no real logic about which methods are duplicated, and the use of `#[rustc_lint_diagnostic]` and `#[track_caller]` attributes vary across the duplicates. This PR removes the duplicated API methods and makes all diagnostic creation and emission go through `DiagCtxt`. It also adds `dcx` getter methods to several types to shorten chains. This approach scales *much* better than API duplication; indeed, the PR adds `dcx()` to numerous types that didn't have API duplication: `TyCtxt`, `LoweringCtxt`, `ConstCx`, `FnCtxt`, `TypeErrCtxt`, `InferCtxt`, `CrateLoader`, `CheckAttrVisitor`, and `Resolver`. These result in a lot of changes from `foo.tcx.sess.emit_err()` to `foo.dcx().emit_err()`. (You could do this with more types, but it gets into diminishing returns territory for types that don't emit many diagnostics.) After all these changes, some call sites are more verbose, some are less verbose, and many are the same. The total number of lines is reduced, mostly because of the removed API duplication. And consistency is increased, because calls to `emit_err` and friends are always preceded with `.dcx()` or `.dcx`. r? `@compiler-errors`
2023-12-25Only regular coroutines have movabilityMichael Goulet-1/+2
2023-12-25Auto merge of #119226 - Mark-Simulacrum:format-efficiency, r=TaKO8Kibors-23/+36
Improve coding efficiency for RawDefId This copies the scheme already used for LazyArray, cutting a couple hundred kilobytes from libcore's metadata.
2023-12-24Auto merge of #119139 - michaelwoerister:cleanup-stable-source-file-id, ↵bors-23/+25
r=cjgillot Unify SourceFile::name_hash and StableSourceFileId This PR adapts the existing `StableSourceFileId` type so that it can be used instead of the `name_hash` field of `SourceFile`. This simplifies a few things that were kind of duplicated before. The PR should also fix issues https://github.com/rust-lang/rust/issues/112700 and https://github.com/rust-lang/rust/issues/115835, but I was not able to reproduce these issues in a regression test. As far as I can tell, the root cause of these issues is that the id of the originating crate is not hashed in the `HashStable` impl of `Span` and thus cache entries that should have been considered invalidated were loaded. After this PR, the `stable_id` field of `SourceFile` includes information about the originating crate, so that ICE should not occur anymore.
2023-12-24Do not store stable crate id in on-disk hash map.Camille GILLOT-1/+3
2023-12-24Auto merge of #119265 - Mark-Simulacrum:remove-cache, r=cjgillotbors-22/+8
Remove metadata decoding DefPathHash cache My expectation is that this cache is largely useless. Decoding a DefPathHash from metadata is essentially a pair of memory loads - there's no heavyweight processing involved. Caching it behind a HashMap just adds extra cost and incurs hashing overheads for the indices. Based on https://github.com/rust-lang/rust/pull/119238.
2023-12-24Auto merge of #119238 - Mark-Simulacrum:def-hash-efficiency, r=cjgillotbors-29/+19
Skip duplicate stable crate ID encoding into metadata Instead, we store just the local crate hash as a bare u64. On decoding, we recombine it with the crate's stable crate ID stored separately in metadata. The end result is that we save ~8 bytes/DefIndex in metadata size. One key detail here is that we no longer distinguish in encoded metadata between present and non-present DefPathHashes. It used to be highly likely we could distinguish as we used DefPathHash::default(), an all-zero representation. However in theory even that is fallible as nothing strictly prevents the StableCrateId from being zero. In review it was pointed out that we should never have a missing hash for a DefIndex anyway, so this shouldn't matter.
2023-12-24Remove more `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-1/+1
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-93/+103
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-23Remove metadata decoding DefPathHash cacheMark Rousskov-22/+8
This cache is largely useless. Decoding a DefPathHash from metadata is essentially a pair of memory loads - there's no heavyweight processing involved. Caching it behind a HashMap just adds extra cost and incurs hashing overheads.
2023-12-23Specialize DefPathHash table to skip crate IDsMark Rousskov-29/+19
Instead, we store just the local crate hash as a bare u64. On decoding, we recombine it with the crate's stable crate ID stored separately in metadata. The end result is that we save ~8 bytes/DefIndex in metadata size. One key detail here is that we no longer distinguish in encoded metadata between present and non-present DefPathHashes. It used to be highly likely we could distinguish as we used DefPathHash::default(), an all-zero representation. However in theory even that is fallible as nothing strictly prevents the StableCrateId from being zero.
2023-12-23Auto merge of #119225 - Mark-Simulacrum:remove-option, r=compiler-errorsbors-3/+3
Avoid redundant Option for cross_crate_inlinable
2023-12-22Split coroutine desugaring kind from sourceMichael Goulet-10/+10
2023-12-22Improve coding efficiency for RawDefIdMark Rousskov-23/+36
This copies the scheme already used for LazyArray, cutting a couple hundred kilobytes from libcore's metadata.
2023-12-22Avoid redundant Option for cross_crate_inlinableMark Rousskov-3/+3
2023-12-22Auto merge of #119173 - compiler-errors:direct-coro-kind, r=TaKO8Kibors-4/+19
Encode `CoroutineKind` directly Probably a quick optimization? r? `@ghost`
2023-12-22Auto merge of #119097 - nnethercote:fix-EmissionGuarantee, r=compiler-errorsbors-19/+12
Fix `EmissionGuarantee` There are some problems with the `DiagCtxt` API related to `EmissionGuarantee`. This PR fixes them. r? `@compiler-errors`