about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2023-03-29Stabilize a portion of 'once_cell'Trevor Gross-1/+1
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
2023-03-17Remove VecMapMichael Goulet-1/+0
2023-03-08Rename `MapInPlace` as `FlatMapInPlace`.Nicholas Nethercote-1/+1
After removing the `map_in_place` method, which isn't much use because modifying every element in a collection such as a `Vec` can be done trivially with iteration.
2023-02-14Refactor refcounted structural_impls via functorsAlan Egerton-0/+1
2023-02-06Make an optimal cold path for query_cache_hitJohn Kåre Alsaker-0/+1
2023-01-18Also remove `#![feature(control_flow_enum)]` where possibleScott McMurray-1/+0
2022-10-27Introduce UnordMap, UnordSet, and UnordBag (see MCP 533)Michael Woerister-0/+2
MCP 533: https://github.com/rust-lang/compiler-team/issues/533 Also, as an example, substitute UnordMap for FxHashMap in used_trait_imports query result.
2022-09-26remove cfg(bootstrap)Pietro Albini-1/+0
2022-09-15Only enable the let_else feature on bootstrapest31-1/+1
On later stages, the feature is already stable. Result of running: rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-08-29Replace `rustc_data_structures::thin_vec::ThinVec` with `thin_vec::ThinVec`.Nicholas Nethercote-1/+0
`rustc_data_structures::thin_vec::ThinVec` looks like this: ``` pub struct ThinVec<T>(Option<Box<Vec<T>>>); ``` It's just a zero word if the vector is empty, but requires two allocations if it is non-empty. So it's only usable in cases where the vector is empty most of the time. This commit removes it in favour of `thin_vec::ThinVec`, which is also word-sized, but stores the length and capacity in the same allocation as the elements. It's good in a wider variety of situation, e.g. in enum variants where the vector is usually/always non-empty. The commit also: - Sorts some `Cargo.toml` dependency lists, to make additions easier. - Sorts some `use` item lists, to make additions easier. - Changes `clean_trait_ref_with_bindings` to take a `ThinVec<TypeBinding>` rather than a `&[TypeBinding]`, because this avoid some unnecessary allocations.
2022-08-18Add diagnostic translation lints to crates that don't emit them5225225-0/+2
2022-07-20Remove unused StableMap and StableSet types from rustc_data_structuresMichael Woerister-2/+0
2022-07-06Allow to create definitions inside the query system.Camille GILLOT-0/+1
2022-06-18Remove `likely!` and `unlikely!` macro from compilerGary Guo-21/+0
2022-05-27libcore: Add `iter::from_generator` which is like `iter::from_fn`, but for ↵Vadim Petrochenkov-25/+0
coroutines instead of functions
2022-05-06Auto merge of #94598 - scottmcm:prefix-free-hasher-methods, r=Amanieubors-0/+1
Add a dedicated length-prefixing method to `Hasher` This accomplishes two main goals: - Make it clear who is responsible for prefix-freedom, including how they should do it - Make it feasible for a `Hasher` that *doesn't* care about Hash-DoS resistance to get better performance by not hashing lengths This does not change rustc-hash, since that's in an external crate, but that could potentially use it in future. Fixes #94026 r? rust-lang/libs --- The core of this change is the following two new methods on `Hasher`: ```rust pub trait Hasher { /// Writes a length prefix into this hasher, as part of being prefix-free. /// /// If you're implementing [`Hash`] for a custom collection, call this before /// writing its contents to this `Hasher`. That way /// `(collection![1, 2, 3], collection![4, 5])` and /// `(collection![1, 2], collection![3, 4, 5])` will provide different /// sequences of values to the `Hasher` /// /// The `impl<T> Hash for [T]` includes a call to this method, so if you're /// hashing a slice (or array or vector) via its `Hash::hash` method, /// you should **not** call this yourself. /// /// This method is only for providing domain separation. If you want to /// hash a `usize` that represents part of the *data*, then it's important /// that you pass it to [`Hasher::write_usize`] instead of to this method. /// /// # Examples /// /// ``` /// #![feature(hasher_prefixfree_extras)] /// # // Stubs to make the `impl` below pass the compiler /// # struct MyCollection<T>(Option<T>); /// # impl<T> MyCollection<T> { /// # fn len(&self) -> usize { todo!() } /// # } /// # impl<'a, T> IntoIterator for &'a MyCollection<T> { /// # type Item = T; /// # type IntoIter = std::iter::Empty<T>; /// # fn into_iter(self) -> Self::IntoIter { todo!() } /// # } /// /// use std::hash::{Hash, Hasher}; /// impl<T: Hash> Hash for MyCollection<T> { /// fn hash<H: Hasher>(&self, state: &mut H) { /// state.write_length_prefix(self.len()); /// for elt in self { /// elt.hash(state); /// } /// } /// } /// ``` /// /// # Note to Implementers /// /// If you've decided that your `Hasher` is willing to be susceptible to /// Hash-DoS attacks, then you might consider skipping hashing some or all /// of the `len` provided in the name of increased performance. #[inline] #[unstable(feature = "hasher_prefixfree_extras", issue = "88888888")] fn write_length_prefix(&mut self, len: usize) { self.write_usize(len); } /// Writes a single `str` into this hasher. /// /// If you're implementing [`Hash`], you generally do not need to call this, /// as the `impl Hash for str` does, so you can just use that. /// /// This includes the domain separator for prefix-freedom, so you should /// **not** call `Self::write_length_prefix` before calling this. /// /// # Note to Implementers /// /// The default implementation of this method includes a call to /// [`Self::write_length_prefix`], so if your implementation of `Hasher` /// doesn't care about prefix-freedom and you've thus overridden /// that method to do nothing, there's no need to override this one. /// /// This method is available to be overridden separately from the others /// as `str` being UTF-8 means that it never contains `0xFF` bytes, which /// can be used to provide prefix-freedom cheaper than hashing a length. /// /// For example, if your `Hasher` works byte-by-byte (perhaps by accumulating /// them into a buffer), then you can hash the bytes of the `str` followed /// by a single `0xFF` byte. /// /// If your `Hasher` works in chunks, you can also do this by being careful /// about how you pad partial chunks. If the chunks are padded with `0x00` /// bytes then just hashing an extra `0xFF` byte doesn't necessarily /// provide prefix-freedom, as `"ab"` and `"ab\u{0}"` would likely hash /// the same sequence of chunks. But if you pad with `0xFF` bytes instead, /// ensuring at least one padding byte, then it can often provide /// prefix-freedom cheaper than hashing the length would. #[inline] #[unstable(feature = "hasher_prefixfree_extras", issue = "88888888")] fn write_str(&mut self, s: &str) { self.write_length_prefix(s.len()); self.write(s.as_bytes()); } } ``` With updates to the `Hash` implementations for slices and containers to call `write_length_prefix` instead of `write_usize`. `write_str` defaults to using `write_length_prefix` since, as was pointed out in the issue, the `write_u8(0xFF)` approach is insufficient for hashers that work in chunks, as those would hash `"a\u{0}"` and `"a"` to the same thing. But since `SipHash` works byte-wise (there's an internal buffer to accumulate bytes until a full chunk is available) it overrides `write_str` to continue to use the add-non-UTF-8-byte approach. --- Compatibility: Because the default implementation of `write_length_prefix` calls `write_usize`, the changed hash implementation for slices will do the same thing the old one did on existing `Hasher`s.
2022-05-06Add a dedicated length-prefixing method to `Hasher`Scott McMurray-0/+1
This accomplishes two main goals: - Make it clear who is responsible for prefix-freedom, including how they should do it - Make it feasible for a `Hasher` that *doesn't* care about Hash-DoS resistance to get better performance by not hashing lengths This does not change rustc-hash, since that's in an external crate, but that could potentially use it in future.
2022-05-04Stabilize `bool::then_some`Josh Triplett-1/+0
2022-04-16Auto merge of #95899 - petrochenkov:modchild2, r=cjgillotbors-0/+25
rustc_metadata: Do not encode unnecessary module children This should remove the syntax context shift and the special case for `ExternCrate` in decoder in https://github.com/rust-lang/rust/pull/95880. This PR also shifts some work from decoding to encoding, which is typically useful for performance (but probably not much in this case). r? `@cjgillot`
2022-04-14make unaligned_references lint deny-by-defaultRalf Jung-1/+0
2022-04-13rustc_metadata: Do not encode unnecessary module childrenVadim Petrochenkov-0/+25
2022-03-04Add SmallStrTomasz Miąsko-0/+1
2022-02-25Switch bootstrap cfgsMark Rousskov-1/+1
2022-02-23Introduce `ChunkedBitSet` and use it for some dataflow analyses.Nicholas Nethercote-0/+2
This reduces peak memory usage significantly for some programs with very large functions, such as: - `keccak`, `unicode_normalization`, and `match-stress-enum`, from the `rustc-perf` benchmark suite; - `http-0.2.6` from crates.io. The new type is used in the analyses where the bitsets can get huge (e.g. 10s of thousands of bits): `MaybeInitializedPlaces`, `MaybeUninitializedPlaces`, and `EverInitializedPlaces`. Some refactoring was required in `rustc_mir_dataflow`. All existing analysis domains are either `BitSet` or a trivial wrapper around `BitSet`, and access in a few places is done via `Borrow<BitSet>` or `BorrowMut<BitSet>`. Now that some of these domains are `ClusterBitSet`, that no longer works. So this commit replaces the `Borrow`/`BorrowMut` usage with a new trait `BitSetExt` containing the needed bitset operations. The impls just forward these to the underlying bitset type. This required fiddling with trait bounds in a few places. The commit also: - Moves `static_assert_size` from `rustc_data_structures` to `rustc_index` so it can be used in the latter; the former now re-exports it so existing users are unaffected. - Factors out some common "clear excess bits in the final word" functionality in `bit_set.rs`. - Uses `fill` in a few places instead of loops.
2022-02-19Adopt let else in more placesest31-0/+1
2022-02-15Rename `PtrKey` as `Interned` and improve it.Nicholas Nethercote-1/+2
In particular, there's now more protection against incorrect usage, because you can only create one via `Interned::new_unchecked`, which makes it more obvious that you must be careful. There are also some tests.
2022-02-01add a rustc::query_stability lintlcnr-0/+1
2021-12-07Make IdFunctor::try_map_id panic-safeAlan Egerton-0/+1
2021-12-05Stop enabling `in_band_lifetimes` in rustc_data_structuresScott McMurray-2/+0
There's a conversation in the tracking issue about possibly unaccepting `in_band_lifetimes`, but it's used heavily in the compiler, and thus there'd need to be a bunch of PRs like this if that were to happen. So here's one to see how much of an impact it has. (Oh, and I removed `nll` while I was here too, since it didn't seem needed. Let me know if I should put that back.)
2021-12-02Remove no-longer used `IdFunctor::map_id`Alan Egerton-1/+0
2021-11-27Delegate from `map_id` to `try_map_id`Alan Egerton-0/+1
2021-10-28Revert "Add rustc lint, warning when iterating over hashmaps"Mark Rousskov-1/+0
2021-10-25Auto merge of #90042 - pietroalbini:1.56-master, r=Mark-Simulacrumbors-1/+0
Bump bootstrap compiler to 1.57 Fixes https://github.com/rust-lang/rust/issues/90152 r? `@Mark-Simulacrum`
2021-10-23update cfg(bootstrap)Pietro Albini-1/+0
2021-10-15allow `potential_query_instability` everywherelcnr-0/+1
2021-10-04Rollup merge of #89508 - jhpratt:stabilize-const_panic, r=joshtriplettJubilee-1/+1
Stabilize `const_panic` Closes #51999 FCP completed in #89006 ```@rustbot``` label +A-const-eval +A-const-fn +T-lang cc ```@oli-obk``` for review (not `r?`'ing as not on lang team)
2021-10-04Stabilize `const_panic`Jacob Pratt-1/+1
2021-10-02Remove various unused feature gatesbjorn3-1/+0
2021-09-17Stabilize `Iterator::map_while`Maybe Waffle-1/+0
2021-09-10rustc: Remove local variable IDs from `Export`sVadim Petrochenkov-0/+1
Local variables can never be exported.
2021-09-08Bump stage0 compiler to 1.56Mark Rousskov-2/+1
2021-07-27Use type_alias_impl_trait instead of min in compiler and libSantiago Pastorino-1/+2
2021-07-23Sort features alphabeticallyYuki Okushi-13/+13
2021-07-23Use `map_while` instead of `take_while` + `map`Yuki Okushi-0/+2
2021-07-22Fix VecMap::iter_mutOli Scherer-0/+1
It used to allow you to mutate the key, even though that can invalidate the map by creating duplicate keys.
2021-06-11Auto merge of #85885 - bjorn3:remove_box_region, r=cjgillotbors-2/+0
Don't use a generator for BoxedResolver The generator is non-trivial and requires unsafe code anyway. Using regular unsafe code without a generator is much easier to follow. Based on #85810 as it touches rustc_interface too.
2021-06-08Inline the rest of box_regionbjorn3-2/+0
2021-06-07Add VecMap to rustc_data_structuresSantiago Pastorino-0/+1
2021-05-31Remove unused feature gatesbjorn3-1/+0
2021-05-31Remove unnecessary unboxed_closures feature usagebjorn3-2/+0
It has been possible to clone closures for a while now