-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deterministic FxHashSet
wrapper
#94188
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
609f649
Modify StableSet with a HashStable implementation.
hameerabbasi 72c9dd7
Attempt at replacing all occurrences.
hameerabbasi fb669bc
Do some suggested changes, push to show compilation errors.
hameerabbasi d505d55
Add stable iteration API.
hameerabbasi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use std::iter::Chain; | ||
|
||
use crate::stable_hasher::ToStableHashKey; | ||
|
||
pub struct StableIterator<I: Iterator> { | ||
inner: I, | ||
} | ||
|
||
impl<T, I: Iterator<Item = T>> StableIterator<I> { | ||
#[inline] | ||
pub fn map<U, F: Fn(T) -> U>(self, f: F) -> StableIterator<impl Iterator<Item = U>> { | ||
StableIterator { inner: self.inner.map(f) } | ||
} | ||
|
||
#[inline] | ||
pub fn into_sorted<HCX>(self, hcx: &HCX) -> Vec<T> | ||
where | ||
T: ToStableHashKey<HCX>, | ||
{ | ||
let mut items: Vec<T> = self.inner.collect(); | ||
items.sort_by_cached_key(|x| x.to_stable_hash_key(hcx)); | ||
items | ||
} | ||
|
||
#[inline] | ||
pub fn any<F: Fn(T) -> bool>(&mut self, f: F) -> bool { | ||
self.inner.any(f) | ||
} | ||
|
||
#[inline] | ||
pub fn all<F: Fn(T) -> bool>(&mut self, f: F) -> bool { | ||
self.inner.all(f) | ||
} | ||
|
||
#[inline] | ||
pub fn chain<J: Iterator<Item = I::Item>>(self, other: StableIterator<J>) -> StableChain<I, J> { | ||
self.inner.chain(other.inner).into() | ||
} | ||
} | ||
|
||
pub trait IntoStableIterator { | ||
type IntoIter: Iterator; | ||
fn into_stable_iter(self) -> StableIterator<Self::IntoIter>; | ||
} | ||
|
||
impl<I: Iterator, S: IntoIterator<Item = I::Item, IntoIter = I>> IntoStableIterator for S { | ||
type IntoIter = I; | ||
|
||
#[inline] | ||
fn into_stable_iter(self) -> StableIterator<I> { | ||
StableIterator { inner: self.into_iter() } | ||
} | ||
} | ||
|
||
pub struct StableChain<I: Iterator, J: Iterator> { | ||
inner: Chain<I, J>, | ||
} | ||
|
||
impl<I: Iterator, J: Iterator<Item = I::Item>> IntoStableIterator for StableChain<I, J> { | ||
type IntoIter = Chain<I, J>; | ||
|
||
#[inline] | ||
fn into_stable_iter(self) -> StableIterator<Self::IntoIter> { | ||
self.inner.into_stable_iter() | ||
} | ||
} | ||
|
||
impl<I: Iterator, J: Iterator> From<Chain<I, J>> for StableChain<I, J> { | ||
#[inline] | ||
fn from(inner: Chain<I, J>) -> Self { | ||
Self { inner } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,23 +3,26 @@ pub mod dependency_format; | |
pub mod exported_symbols; | ||
pub mod lang_items; | ||
pub mod lib_features { | ||
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; | ||
use rustc_data_structures::{fx::FxHashMap, stable_set::StableSet}; | ||
use rustc_span::symbol::Symbol; | ||
|
||
use crate::ty::TyCtxt; | ||
|
||
#[derive(HashStable, Debug)] | ||
pub struct LibFeatures { | ||
// A map from feature to stabilisation version. | ||
pub stable: FxHashMap<Symbol, Symbol>, | ||
pub unstable: FxHashSet<Symbol>, | ||
pub unstable: StableSet<Symbol>, | ||
} | ||
|
||
impl LibFeatures { | ||
pub fn to_vec(&self) -> Vec<(Symbol, Option<Symbol>)> { | ||
pub fn to_vec(&self, tcx: TyCtxt<'_>) -> Vec<(Symbol, Option<Symbol>)> { | ||
let hcx = tcx.create_stable_hashing_context(); | ||
let mut all_features: Vec<_> = self | ||
.stable | ||
.iter() | ||
.map(|(f, s)| (*f, Some(*s))) | ||
.chain(self.unstable.iter().map(|f| (*f, None))) | ||
.chain(self.unstable.sorted_vector(&hcx).into_iter().map(|f| (*f, None))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same because of the sort below. |
||
.collect(); | ||
all_features.sort_unstable_by(|a, b| a.0.as_str().partial_cmp(b.0.as_str()).unwrap()); | ||
all_features | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.