about summary refs log tree commit diff
path: root/compiler/rustc_span/src/def_id.rs
AgeCommit message (Collapse)AuthorLines
2025-06-22Hash less while hashing def-ids.Camille GILLOT-3/+15
2025-02-16Move hashes from rustc_data_structure to rustc_hashes so they can be shared ↵Ben Kimock-3/+2
with rust-analyzer
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-3/+5
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-22Ensure careful consideration is given by implsAlan Egerton-1/+3
Added an associated `const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED` to the `StableOrd` trait to ensure that implementors carefully consider whether the trait's contract is upheld, as incorrect implementations can cause miscompilations.
2024-06-12Un-unsafe the `StableOrd` traitAlan Egerton-2/+2
Whilst incorrect implementations of this trait can cause miscompilation, they cannot cause memory unsafety in rustc.
2024-04-29Remove `extern crate rustc_macros` from numerous crates.Nicholas Nethercote-1/+1
2024-04-03rustc_index: Add a `ZERO` constant to index typesVadim Petrochenkov-1/+1
It is commonly used.
2024-03-27Ensure no one re-adds `Partial/Ord` impls for `DefId`Oli Scherer-0/+6
2024-03-27Remove `DefId`'s `Partial/Ord` implsOli Scherer-18/+0
2024-01-06Auto merge of #119478 - bjorn3:no_serialize_specialization, r=wesleywiserbors-43/+4
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-04Make iteration order of region_scope_tree query stableMichael Woerister-1/+17
2023-12-31Remove almost all uses of specialization from the metadata encoding codebjorn3-43/+4
2023-12-23Specialize DefPathHash table to skip crate IDsMark Rousskov-2/+0
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-11-28Remove a comment.Nicholas Nethercote-1/+0
It was merged by accident in a previous PR.
2023-11-22Replace `no_ord_impl` with `orderable`.Nicholas Nethercote-0/+2
Similar to the previous commit, this replaces `newtype_index`'s opt-out `no_ord_impl` attribute with the opt-in `orderable` attribute.
2023-11-22Replace `custom_encodable` with `encodable`.Nicholas Nethercote-2/+1
By default, `newtype_index!` types get a default `Encodable`/`Decodable` impl. You can opt out of this with `custom_encodable`. Opting out is the opposite to how Rust normally works with autogenerated (derived) impls. This commit inverts the behaviour, replacing `custom_encodable` with `encodable` which opts into the default `Encodable`/`Decodable` impl. Only 23 of the 59 `newtype_index!` occurrences need `encodable`. Even better, there were eight crates with a dependency on `rustc_serialize` just from unused default `Encodable`/`Decodable` impls. This commit removes that dependency from those eight crates.
2023-08-14Use `{Local}ModDefId` in many queriesNilstrieb-1/+1
2023-08-13Add typed `{Local}DefId` for modulesNilstrieb-0/+95
This allows for better type safety in the compiler and also improves the documentation for many things, making it clear that they expect modules.
2023-05-17Only depend on CFG_VERSION in rustc_interfacejyn-2/+7
this avoids having to rebuild the whole compiler on each commit when `omit-git-hash = false`.
2023-04-24Split `{Idx, IndexVec, IndexSlice}` into their own modulesMaybe Waffle-1/+1
2023-04-18Add #[inline] to some new functionsBen Kimock-0/+1
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
2023-04-18Store hashes in special types so they aren't accidentally encoded as numbersBen Kimock-20/+18
2023-03-21Eagerly intern and check CrateNum/StableCrateId collisionsOli Scherer-1/+5
2023-03-03Match unmatched backticks in comments in compiler/est31-1/+1
2023-02-16Replace some `then`s with some `then_some`sMaybe Waffle-1/+1
2023-02-16`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`Maybe Waffle-2/+2
2023-02-05rustc_metadata: Encode/decode `DefPathHash`es without an `Option`Vadim Petrochenkov-0/+6
2023-01-05Fix `uninlined_format_args` for some compiler cratesnils-1/+1
Convert all the crates that have had their diagnostic migration completed (except save_analysis because that will be deleted soon and apfloat because of the licensing problem).
2022-12-18A few small cleanups for `newtype_index`Nilstrieb-3/+2
Remove the `..` from the body, only a few invocations used it and it's inconsistent with rust syntax. Use `;` instead of `,` between consts. As the Rust syntax gods inteded.
2022-12-18Make `#[debug_format]` an attribute in `newtype_index`Nilstrieb-2/+2
This removes the `custom` format functionality as its only user was trivially migrated to using a normal format. If a new use case for a custom formatting impl pops up, you can add it back.
2022-12-18Make `#[custom_encodable]` an attribute for `newtype_index`Nilstrieb-3/+2
Makes the syntax a little more rusty.
2022-12-08Rollup merge of #105423 - oli-obk:symbols, r=jackh726Matthias Krüger-3/+5
Use `Symbol` for the crate name instead of `String`/`str` It always got converted to a symbol anyway
2022-12-07Use `Symbol` for the crate name instead of `String`/`str`Oli Scherer-3/+5
2022-12-06Cleanup macro-expanded code in `rustc_type_ir`Maybe Waffle-1/+1
2022-11-25Prefer not accessing the private field of newtype_index typesOli Scherer-1/+1
2022-09-27Manually order `DefId` on 64-bit big-endianJosh Stone-1/+19
`DefId` uses different field orders on 64-bit big-endian vs. others, in order to optimize its `Hash` implementation. However, that also made it derive different lexical ordering for `PartialOrd` and `Ord`. That caused spurious differences wherever `DefId`s are sorted, like the candidate sources list in `report_method_error`. Now we manually implement `PartialOrd` and `Ord` on 64-bit big-endian to match the same lexical ordering as other targets, fixing at least one test, `src/test/ui/methods/method-ambig-two-traits-cross-crate.rs`.
2022-09-10rustc_error, rustc_private, rustc_ast: Switch to stable hash containersNiklas Jonsson-2/+7
2022-09-07rustc: Parameterize `ty::Visibility` over used IDVadim Petrochenkov-0/+6
It allows using `LocalDefId` instead of `DefId` when possible, and also encode cheaper `Visibility<DefIndex>` into metadata.
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