summary refs log tree commit diff
path: root/compiler/rustc_span/src/def_id.rs
AgeCommit message (Collapse)AuthorLines
2022-06-08Use delayed error handling for `Encodable` and `Encoder` infallible.Nicholas Nethercote-8/+8
There are two impls of the `Encoder` trait: `opaque::Encoder` and `opaque::FileEncoder`. The former encodes into memory and is infallible, the latter writes to file and is fallible. Currently, standard `Result`/`?`/`unwrap` error handling is used, but this is a bit verbose and has non-trivial cost, which is annoying given how rare failures are (especially in the infallible `opaque::Encoder` case). This commit changes how `Encoder` fallibility is handled. All the `emit_*` methods are now infallible. `opaque::Encoder` requires no great changes for this. `opaque::FileEncoder` now implements a delayed error handling strategy. If a failure occurs, it records this via the `res` field, and all subsequent encoding operations are skipped if `res` indicates an error has occurred. Once encoding is complete, the new `finish` method is called, which returns a `Result`. In other words, there is now a single `Result`-producing method instead of many of them. This has very little effect on how any file errors are reported if `opaque::FileEncoder` has any failures. Much of this commit is boring mechanical changes, removing `Result` return values and `?` or `unwrap` from expressions. The more interesting parts are as follows. - serialize.rs: The `Encoder` trait gains an `Ok` associated type. The `into_inner` method is changed into `finish`, which returns `Result<Vec<u8>, !>`. - opaque.rs: The `FileEncoder` adopts the delayed error handling strategy. Its `Ok` type is a `usize`, returning the number of bytes written, replacing previous uses of `FileEncoder::position`. - Various methods that take an encoder now consume it, rather than being passed a mutable reference, e.g. `serialize_query_result_cache`.
2022-06-03Inline many methods of Encoderbjorn3-5/+2
They aren't overridden anyway
2022-06-03Remove all names from Encoderbjorn3-3/+3
They aren't used anymore now that the json format has been removed
2022-05-07Remove closures on `expect_local` to apply `#[track_caller]`Yuki Okushi-1/+6
2022-05-06Add `track_caller` to `DefId::expect_local()`Yuki Okushi-0/+1
2022-04-17Stop using CRATE_DEF_INDEX.Camille GILLOT-2/+13
`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.
2022-03-08add `#[rustc_pass_by_value]` to more typeslcnr-2/+3
2022-02-20Delete Decoder::read_struct_fieldMark Rousskov-4/+1
2022-02-20Delete Decoder::read_structMark Rousskov-2/+2
2022-01-22Make `Decodable` and `Decoder` infallible.Nicholas Nethercote-11/+9
`Decoder` has two impls: - opaque: this impl is already partly infallible, i.e. in some places it currently panics on failure (e.g. if the input is too short, or on a bad `Result` discriminant), and in some places it returns an error (e.g. on a bad `Option` discriminant). The number of places where either happens is surprisingly small, just because the binary representation has very little redundancy and a lot of input reading can occur even on malformed data. - json: this impl is fully fallible, but it's only used (a) for the `.rlink` file production, and there's a `FIXME` comment suggesting it should change to a binary format, and (b) in a few tests in non-fundamental ways. Indeed #85993 is open to remove it entirely. And the top-level places in the compiler that call into decoding just abort on error anyway. So the fallibility is providing little value, and getting rid of it leads to some non-trivial performance improvements. Much of this commit is pretty boring and mechanical. Some notes about a few interesting parts: - The commit removes `Decoder::{Error,error}`. - `InternIteratorElement::intern_with`: the impl for `T` now has the same optimization for small counts that the impl for `Result<T, E>` has, because it's now much hotter. - Decodable impls for SmallVec, LinkedList, VecDeque now all use `collect`, which is nice; the one for `Vec` uses unsafe code, because that gave better perf on some benchmarks.
2022-01-12Rename environment variable for overriding rustc versionpierwill-2/+2
2022-01-11Auto merge of #92012 - llogiq:repr-c-def-id, r=michaelwoeristerbors-1/+8
Make `DefId` `repr(C)`, optimize big-endian field order r? `@michaelwoerister`
2022-01-07Fix typo in `StableCrateId` docspierwill-2/+2
2022-01-04Make `DefId` `repr(C)`, optimize big-endian field orderAndre Bogus-1/+8
2021-12-30Add negative `impl` for `Ord`, `PartialOrd` on `LocalDefId`pierwill-5/+11
Add comment about why `LocalDefId` should not be `Ord` Also fix some formatting in the doc comment.
2021-12-22Remove `PartialOrd` and `Ord` from `LocalDefId`pierwill-1/+1
Implement `Ord`, `PartialOrd` for SpanData
2021-12-16Auto merge of #89836 - pierwill:fix-85142-crate-hash, r=wesleywiserbors-6/+21
Include rustc version in `rustc_span::StableCrateId` `rustc_span::def_id::StableCrateId` is a hash of various data about a crate during compilation. This PR includes the version of `rustc` in the input when computing this hash. From a cursory reading of [RFC 2603](https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html), this appears to be acceptable within that design. In order to pass the `mir-opt` and `ui` test suites, this adds new [normalization for hashes and symbol names in `compiletest`](https://github.com/rust-lang/rust/pull/89836/files#diff-03a0567fa80ca04ed5a55f9ac5c711b4f84659be2d0ac4a984196d581c04f76b). These are enabled by default, but we might prefer it to be configurable. In the UI tests, I had to truncate a significant amount of error annotations in v0 symbols (and maybe some legacy) in order to get the normalization to work correctly. (See https://github.com/rust-lang/rust/issues/90116.) Closes #85142.
2021-12-13Add run-make-fulldeps testpierwill-5/+14
Implement RUSTC_FORCE_INCR_COMP_ARTIFACT_HEADER Also makes minor docs edits.
2021-12-13Include rustc version in `rustc_span::StableCrateId`pierwill-5/+11
Normalize symbol hashes in compiletest. Remove DefId sorting
2021-12-10manually implement `Hash` for `DefId`Andre Bogus-5/+31
This also reorders the fields to reduce the assembly operations for hashing and changes two UI tests that depended on the former ordering because of hashmap iteration order.
2021-07-17Encode ExpnId using ExpnHash for incr. comp.Camille GILLOT-1/+1
2021-07-06Revert "Revert "Merge CrateDisambiguator into StableCrateId""bjorn3-8/+32
This reverts commit 8176ab8bc18fdd7d3c2cf7f720c51166364c33a3.
2021-06-11Sprinkle inline.Camille GILLOT-5/+6
2021-06-11Hash DefId in rustc_span.Camille GILLOT-3/+38
2021-06-07Auto merge of #85903 - bjorn3:rustc_serialize_cleanup, r=varkorbors-6/+6
Remove unused functions and arguments from rustc_serialize
2021-06-07Revert "Merge CrateDisambiguator into StableCrateId"bjorn3-32/+8
This reverts commit d0ec85d3fb6d322496cb8f4bc1c21e19f23284ad.
2021-06-02Miscellaneous inlining improvementsTomasz Miąsko-0/+2
2021-06-01Auto merge of #85829 - bjorn3:simplify_crate_num, r=jackh726bors-60/+4
Remove CrateNum::ReservedForIncrCompCache It's only use is easily replaceable with `Option<CrateNum>`.
2021-06-01Remove unused functions and arguments from rustc_serializebjorn3-6/+6
2021-05-30Remove CrateNum::ReservedForIncrCompCachebjorn3-60/+4
2021-05-30Merge CrateDisambiguator into StableCrateIdbjorn3-8/+32
2021-03-27Remove (lots of) dead codeJoshua Nelson-0/+2
Found with https://github.com/est31/warnalyzer. Dubious changes: - Is anyone else using rustc_apfloat? I feel weird completely deleting x87 support. - Maybe some of the dead code in rustc_data_structures, in case someone wants to use it in the future? - Don't change rustc_serialize I plan to scrap most of the json module in the near future (see https://github.com/rust-lang/compiler-team/issues/418) and fixing the tests needed more work than I expected. TODO: check if any of the comments on the deleted code should be kept.
2021-03-07Auto merge of #81635 - michaelwoerister:structured_def_path_hash, r=pnkfelixbors-0/+87
Let a portion of DefPathHash uniquely identify the DefPath's crate. This allows to directly map from a `DefPathHash` to the crate it originates from, without constructing side tables to do that mapping -- something that is useful for incremental compilation where we deal with `DefPathHash` instead of `DefId` a lot. It also allows to reliably and cheaply check for `DefPathHash` collisions which allows the compiler to gracefully abort compilation instead of running into a subsequent ICE at some random place in the code. The following new piece of documentation describes the most interesting aspects of the changes: ```rust /// A `DefPathHash` is a fixed-size representation of a `DefPath` that is /// stable across crate and compilation session boundaries. It consists of two /// separate 64-bit hashes. The first uniquely identifies the crate this /// `DefPathHash` originates from (see [StableCrateId]), and the second /// uniquely identifies the corresponding `DefPath` within that crate. Together /// they form a unique identifier within an entire crate graph. /// /// There is a very small chance of hash collisions, which would mean that two /// different `DefPath`s map to the same `DefPathHash`. Proceeding compilation /// with such a hash collision would very probably lead to an ICE and, in the /// worst case, to a silent mis-compilation. The compiler therefore actively /// and exhaustively checks for such hash collisions and aborts compilation if /// it finds one. /// /// `DefPathHash` uses 64-bit hashes for both the crate-id part and the /// crate-internal part, even though it is likely that there are many more /// `LocalDefId`s in a single crate than there are individual crates in a crate /// graph. Since we use the same number of bits in both cases, the collision /// probability for the crate-local part will be quite a bit higher (though /// still very small). /// /// This imbalance is not by accident: A hash collision in the /// crate-local part of a `DefPathHash` will be detected and reported while /// compiling the crate in question. Such a collision does not depend on /// outside factors and can be easily fixed by the crate maintainer (e.g. by /// renaming the item in question or by bumping the crate version in a harmless /// way). /// /// A collision between crate-id hashes on the other hand is harder to fix /// because it depends on the set of crates in the entire crate graph of a /// compilation session. Again, using the same crate with a different version /// number would fix the issue with a high probability -- but that might be /// easier said then done if the crates in questions are dependencies of /// third-party crates. /// /// That being said, given a high quality hash function, the collision /// probabilities in question are very small. For example, for a big crate like /// `rustc_middle` (with ~50000 `LocalDefId`s as of the time of writing) there /// is a probability of roughly 1 in 14,750,000,000 of a crate-internal /// collision occurring. For a big crate graph with 1000 crates in it, there is /// a probability of 1 in 36,890,000,000,000 of a `StableCrateId` collision. ``` Given the probabilities involved I hope that no one will ever actually see the error messages. Nonetheless, I'd be glad about some feedback on how to improve them. Should we create a GH issue describing the problem and possible solutions to point to? Or a page in the rustc book? r? `@pnkfelix` (feel free to re-assign)
2021-02-15Only store a LocalDefId in hir::Item.Camille GILLOT-0/+4
Items are guaranteed to be HIR owner.
2021-02-04Add unit test to ensure that both parts of a DefPathHash depend on the ↵Michael Woerister-0/+6
defining crate's ID.
2021-02-02Let a portion of DefPathHash uniquely identify the DefPath's crate.Michael Woerister-0/+81
This allows to directly map from a DefPathHash to the crate it originates from, without constructing side tables to do that mapping. It also allows to reliably and cheaply check for DefPathHash collisions.
2020-10-06Add some docs to rustdoc::clean::inline and def_id functionsLzu Tao-0/+1
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-08-30mv compiler to compiler/mark-0/+280