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

Need to note unordering-ge for Map/Hash/QuantHash/Bag/Set/Mix/BagHah/SetHash/MixHash #2174

Open
zoffixznet opened this issue Jul 13, 2018 · 5 comments
Labels
docs Documentation issue (primary issue type) update part of "docs" - indicates this is an update for an existing section; rewrite, clarification, etc.

Comments

@zoffixznet
Copy link
Contributor

zoffixznet commented Jul 13, 2018

<Altreus> Hmm, the docs for Hash don't say whether order is preserved.

I don't know if the spec guarantees that the hashy types are unordered, but that info should probably mentioned (if it's not part of spec, then maybe say that some implementation keep it unordered?)

Also, it should be noted somewhere that some methods like .Str, .gist, and .perl do sort the hashy type (this is only partially implemented by Rakudo; filed as R#131244).

@labster
Copy link
Contributor

labster commented Jul 13, 2018

Given that Rakudo used to randomize Hash keys on purpose back when we used an ordered implementation, I think we can assume that the intent is for Hash types not to preserve order.

@jnthn
Copy link
Contributor

jnthn commented Jul 13, 2018

Given it's security that is driving the randomization, it might be reasonable for the spec to guarantee it.

@samcv
Copy link
Collaborator

samcv commented Jul 13, 2018

From my perspective:

Hashes are not guaranteed to retain order, in fact the user should not expect it to. But I also don't think that we should have the spec guarentee that it is randomized.

I see it as an implementation detail.

Essentially the issue that randomization solves for us is revealing information about how the hash is laid out in memory and which hashes end up in which buckets. If an attacker can know insertion order (which we assume they know since they are inserting keys) plus the order of iteration, they can figure out which items are in the same buckets.

Whereas if an implementation retained insertion order then iteration order would only reveal insertion order which an attacker would already know (they are the one inserting the keys).

So things must either be ordered by either insertion order, or sufficiently randomized. In between reveals information we don't want to provide.

Both ruby and python in their latest versions have an implementation that retains insertion order. Although it is not quite as fast as an implementation that does not worry about insertion order, we should keep in mind that there may be VM's/runtimes Perl 6 may run on and they may have insertion order retention.

@JJ JJ added the docs Documentation issue (primary issue type) label Jul 14, 2018
@JJ JJ changed the title Need to note unordering-ge for Map/Hash/QuantHash/Bag/Set/Mix/BagHah/SetHashMixHash Need to note unordering-ge for Map/Hash/QuantHash/Bag/Set/Mix/BagHah/SetHash/MixHash Jul 14, 2018
@JJ JJ added the update part of "docs" - indicates this is an update for an existing section; rewrite, clarification, etc. label Nov 30, 2018
@coke coke assigned coke and unassigned coke Feb 10, 2023
@coke coke added this to the 2023-First Quarter milestone Feb 10, 2023
@cfa
Copy link
Contributor

cfa commented Mar 7, 2023

The title of this issue is confusing (what does "unordering-ge" mean?).

Anyway, here's what I found after a quick skim of the docs:

  • Map: "Note that the order in which keys, values and pairs are retrieved is generally arbitrary, but the keys, values and pairs methods return them always in the same order when called on the same object."
  • Hash: "Although the order of the hashes is guaranteed to be random in every single call, still successive calls to .keys and .values are guaranteed to return them in the same order…"
    • Question: is "guaranteed to be random" definitely the case? CC @lizmat
  • QuantHash seems to be lacking mention of ordering.
    • I'm not sure how relevant it is here? CC @lizmat
  • Bag: "A Bag is an immutable bag/multiset implementing Associative, meaning a collection of distinct elements in no particular order…"
  • BagHash: "A BagHash is a mutable bag/multiset, meaning a collection of distinct items in no particular order…"
  • Mix: "A Mix is an immutable collection of distinct elements in no particular order"
  • Set: "A Set is an immutable set, meaning a collection of distinct elements in no particular order"
  • SetHash: "A SetHash is a mutable set, meaning a collection of distinct elements in no particular order."
  • MixHash: "A MixHash is a mutable mix, meaning a collection of distinct elements in no particular order"

@coke
Copy link
Collaborator

coke commented Mar 7, 2023

The title of this issue is confusing (what does "unordering-ge" mean?).

Turning it into a noun, just "the fact that it is not ordered." (I would have used -age, like package)

@coke coke modified the milestones: 2023-Quarter 1, 2023-Quarter 2 Apr 1, 2023
@coke coke modified the milestones: 2023-Quarter 2, 2023-Quarter 3 Jul 12, 2023
@coke coke modified the milestones: 2023-Quarter 3, 2023-Quarter 4 Oct 8, 2023
@coke coke modified the milestones: 2023-Quarter 4, 2024-Quarter-2 Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type) update part of "docs" - indicates this is an update for an existing section; rewrite, clarification, etc.
Projects
None yet
Development

No branches or pull requests

7 participants