Skip to content
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

data_structures: Add deterministic FxHashMap and FxHashSet wrappers #64131

Merged
merged 1 commit into from
Sep 29, 2019

Conversation

shivan1b
Copy link
Contributor

@shivan1b shivan1b commented Sep 3, 2019

StableMap
A wrapper for FxHashMap that allows to insert, remove, get, get_mut and convert a hashmap into a sorted vector using the method into_sorted_vector but no iteration support.

StableSet
A wrapper for FxHashSet that allows to insert, remove, get and convert a hashset into a sorted vector using the method into_sorted_vector but no iteration support.

Addresses issue #63713

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cramertj (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 3, 2019
@shivan1b
Copy link
Contributor Author

shivan1b commented Sep 3, 2019

Hi @bjorn3!
Could you please check if this meets the requirements of the corresponding issue?
Please note that this does not have the "convertion to a sorted vec." support. I learned the basics of HashMap and checked a few functions, not sure which function does this exactly, could you please point me to that?
Thank you.

@shivan1b
Copy link
Contributor Author

shivan1b commented Sep 3, 2019

r? @bjorn3

@Mark-Simulacrum
Copy link
Member

Please note that the examples above are NOT a part of the commit message.

But they will be if we decide to merge this (bors includes PR message in merge commit).


I'd also like to see this called something like StableMap perhaps or DeterministicMap, since otherwise the determinism aspect is a bit lost in the naming (and since we're likely almost universally using this once we migrate the compiler, it would be good to separate it a bit).


@Mark-Simulacrum
Copy link
Member

We'll probably want a Set variant of the map as well.


For sorted vector support something like the following would work:

fn into_sorted_vector(self) -> Vec<(K, V)> /* or Vec<T> */
where K: PartialOrd,
           V: PartialOrd,
{
    let mut v = self.base.into_iter().collect::<Vec<_>>();
    v.unstable_sort(); // this is interesting in that it's unstable but we're not actually adding instability here since the underlying map already has an unstable iteration order
    v
}

Copy link
Member

@bjorn3 bjorn3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rustfmt dfx.rs (but not the rest of the files, so you will need to run rustfmt /path/to/dfx.rs instead of cargo fmt.)

Apart from a few nits this looks good. @Mark-Simulacrum should this PR contain a first user of the new api, or can that be done in a follow-up?

src/librustc_data_structures/dfx.rs Outdated Show resolved Hide resolved
src/librustc_data_structures/dfx.rs Outdated Show resolved Hide resolved
@shivan1b
Copy link
Contributor Author

shivan1b commented Sep 3, 2019

Please note that the examples above are NOT a part of the commit message.

But they will be if we decide to merge this (bors includes PR message in merge commit).

Right. Forgot about it. I shall remove them before merging unless you think it makes sense to have them as a part of commit message?

I'd also like to see this called something like StableMap perhaps or DeterministicMap, since otherwise the determinism aspect is a bit lost in the naming (and since we're likely almost universally using this once we migrate the compiler, it would be good to separate it a bit).

Shall I go with DeterministickMap then? Should the module name also be changed from dfx to deterministic_map ?

@bjorn3
Copy link
Member

bjorn3 commented Sep 3, 2019

I prefer StableMap as it is shorter, which means it is more likely to be picked over FxHashMap.

@shivan1b
Copy link
Contributor Author

shivan1b commented Sep 3, 2019

We'll probably want a Set variant of the map as well.

Sure. Should I be creating a separate issue for this?

For sorted vector support something like the following would work:

fn into_sorted_vector(self) -> Vec<(K, V)> /* or Vec<T> */
where K: PartialOrd,
           V: PartialOrd,
{
    let mut v = self.base.into_iter().collect::<Vec<_>>();
    v.unstable_sort(); // this is interesting in that it's unstable but we're not actually adding instability here since the underlying map already has an unstable iteration order
    v
}

Thank you very much!

@Mark-Simulacrum
Copy link
Member

I think adding the set in this PR makes sense; it should be minimally difficult to do so, hopefully.

Right. Forgot about it. I shall remove them before merging unless you think it makes sense to have them as a part of commit message?

Yeah, I don't think the examples are too useful.

Apart from a few nits this looks good. @Mark-Simulacrum should this PR contain a first user of the new api, or can that be done in a follow-up?

I think that moving the compiler over can be done in followup PRs. It'll likely be fairly straightforward (mostly just search and replace on FxHash{Map,Set}).

src/librustc_data_structures/stable_map.rs Outdated Show resolved Hide resolved
src/librustc_data_structures/stable_map.rs Outdated Show resolved Hide resolved
src/librustc_data_structures/stable_map.rs Outdated Show resolved Hide resolved
src/librustc_data_structures/stable_map.rs Outdated Show resolved Hide resolved
src/librustc_data_structures/stable_map.rs Show resolved Hide resolved
src/librustc_data_structures/stable_map.rs Show resolved Hide resolved
src/librustc_data_structures/stable_map.rs Outdated Show resolved Hide resolved
@shivan1b shivan1b changed the title data_structures: Add a deterministic FxHashMap wrapper data_structures: Add a deterministic FxHashMap and FxHashSet wrapper Sep 10, 2019
@shivan1b shivan1b changed the title data_structures: Add a deterministic FxHashMap and FxHashSet wrapper data_structures: Add a deterministic FxHashMap and FxHashSet wrappers Sep 10, 2019
@shivan1b shivan1b changed the title data_structures: Add a deterministic FxHashMap and FxHashSet wrappers data_structures: Add deterministic FxHashMap and FxHashSet wrappers Sep 10, 2019
@Alexendoo
Copy link
Member

Ping from triage, any updates? @cramertj

@Mark-Simulacrum
Copy link
Member

r? @Mark-Simulacrum

r=me with commits squashed into one

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 22, 2019
@JohnCSimon
Copy link
Member

Ping from triage:
This is marked as "waiting on author"
@shivan1b can you address the comments from @Mark-Simulacrum ?
Thanks.

StableMap
A wrapper for FxHashMap that allows to insert, remove, get and get_mut
but no iteration support.

StableSet
A wrapper for FxHashSet that allows to insert, remove, get and create a
sorted vector from a hashset but no iteration support.
@shivan1b
Copy link
Contributor Author

Sorry @JohnCSimon for having missed that.
r? @Mark-Simulacrum

@Mark-Simulacrum
Copy link
Member

@bors r+ rollup

Thanks!

@bors
Copy link
Contributor

bors commented Sep 28, 2019

📌 Commit 800bd3a has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 28, 2019
Centril added a commit to Centril/rust that referenced this pull request Sep 28, 2019
…=Mark-Simulacrum

data_structures: Add deterministic FxHashMap and FxHashSet wrappers

StableMap
A wrapper for FxHashMap that allows to `insert`, `remove`, `get`, `get_mut` and convert a hashmap into a sorted vector using the method `into_sorted_vector` but no iteration support.

StableSet
A wrapper for FxHashSet that allows to `insert`, `remove`, `get` and convert a hashset into a sorted vector using the method `into_sorted_vector` but no iteration support.

Addresses issue rust-lang#63713
bors added a commit that referenced this pull request Sep 28, 2019
Rollup of 10 pull requests

Successful merges:

 - #64131 (data_structures: Add deterministic FxHashMap and FxHashSet wrappers)
 - #64387 (Fix redundant semicolon lint interaction with proc macro attributes)
 - #64678 (added more context for duplicate lang item errors (fixes #60561))
 - #64763 (Add E0734 and its long explanation)
 - #64793 (Fix format macro expansions spans to be macro-generated)
 - #64837 (Improve wording in documentation of MaybeUninit)
 - #64852 (Print ParamTy span when accessing a field (#52082))
 - #64875 (Upgrade async/await to "used" keywords.)
 - #64876 (Fix typo in intrinsics op safety)
 - #64880 (Slice docs: fix typo)

Failed merges:

r? @ghost
@bors bors merged commit 800bd3a into rust-lang:master Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants