Skip to content

Fix HashDict so that key comparison uses exact match #1177

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

Merged
merged 1 commit into from
Jun 3, 2013

Conversation

fishcakez
Copy link
Member

This change means that a HashDict is nolonger ordered. Previously
HashDicts did some ordering and for small sizes were fully ordered.
However this meant that keys which compared equal (==) but not exactly
equal (===) would be considered different for large sizes but
equivalent for small sizes. This ambiguity occured because hashes are
only equal when terms are exactly equal (===).

See github issue #1171 for examples, and #1175 for some discussion.

Note: If assumptions were made about the form of a HashDict they may
nolonger be valid. Particularly that HashDicts can nolonger be reliably
pattern matched on for equality.

Sorry for the issue spam, can't get the github API to work to add a PR to existing issue.

@josevalim
Copy link
Member

Jamie, couldn't we leave the Dict "ordered" but simply stop using keyfind
for the lookup?

I put ordered in between quotes because just the buckets are ordered.
Overall there is no order and people should not expect to have one.

Thank you!

José Valim
www.plataformatec.com.br
Skype: jv.ptec
Founder and Lead Developer

@josevalim
Copy link
Member

Oops, iPhone autocompleted James into Jamie. :)

José Valim
www.plataformatec.com.br
Skype: jv.ptec
Founder and Lead Developer

This change means that HashDict buckets are nolonger strictly ordered.
Previously keys which compared equal (==) but not exactly equal (===)
would be considered different for large sizes but equivalent for small
sizes. This ambiguity occured because hashes are only equal when terms
are exactly equal (===), so both now use exact (===) key comparisons.
Small HashDicts are still a single ordered list and large HashDicts
contain ordered buckets. Both of these may contain keys that compare
equal (==) but are not exactly equal (===), should these keys be present
in the same list or bucket the ordering of these keys (relative to each
other) is undefined.

See github issue elixir-lang#1171 for examples.

Note: If assumptions were made about the form of a HashDict they may
nolonger be valid. Particularly that HashDicts can nolonger be reliably
pattern matched on for equality.
@fishcakez
Copy link
Member Author

Forgot to reply saying I'd updated the PR.

On 3 June 2013 01:05, José Valim notifications@github.com wrote:

Oops, iPhone autocompleted James into Jamie. :)

José Valim
www.plataformatec.com.br
Skype: jv.ptec
Founder and Lead Developer


Reply to this email directly or view it on GitHubhttps://github.com//pull/1177#issuecomment-18816841
.

josevalim pushed a commit that referenced this pull request Jun 3, 2013
Fix HashDict so that key comparison uses exact match
@josevalim josevalim merged commit 3918b88 into elixir-lang:master Jun 3, 2013
@alexrp
Copy link

alexrp commented Jun 6, 2013

@josevalim can you please make a hotfix release (say 0.9.1) with this fix? I think the bug was bad enough to warrant a release. In particular, I'll depend entirely on HashDict in the Flect compiler for most semantic information, and Flect is now going to follow stable Elixir releases instead of master.

@josevalim
Copy link
Member

@alexrp Yes, I agree on a release. I just need time as I am oversees right now and there is one extra small thing I want to include in this release.

@alexrp
Copy link

alexrp commented Jun 6, 2013

OK, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants