# DataType hash differs per patch version and OS

**URL:** <https://discourse.julialang.org/t/datatype-hash-differs-per-patch-version-and-os/48827>\
**Category:** General Usage\
**Created:** [October 22, 2020, 3:42pm UTC](https://discourse.julialang.org/t/datatype-hash-differs-per-patch-version-and-os/48827 "2020-10-22T15:42:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![racinmat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/racinmat/32/11715_2.png) [@racinmat](https://discourse.julialang.org/u/racinmat)\
**Post date:** [October 22, 2020, 3:42pm UTC](https://discourse.julialang.org/t/datatype-hash-differs-per-patch-version-and-os/48827/1 "2020-10-22T15:42:36Z")

</div>

I noticed `hash(Float32)` returns different value on each julia version.

While other `hash` functions return same hash for same value, e.g.

```julia
julia> hash("a")
0xfa232f94411b00cd

```

is same for Julia versions 1.3.1, 1.5.0, 1.5.1, 1.5.2.  
But for `hash(Float32)` it’s different for each version, it’s returning different things, these are values are observed.

```julia
julia> hash(Float32)
0x7bb4922dfd8d6f8a
julia> hash(Float32)
0x2ee851e9579d5f99
julia> hash(Float32)
0x35768f5f3a96aad1
julia> hash(Float32)
0xd237962f65c4d373
julia> hash(Float32)
0x80b1a44c1d020e80

```

is this intended, or a bug?  
And if it’s intended, what is the reason why this happens?

And also, why is it different for windows and linux?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 22, 2020, 4:05pm UTC](https://discourse.julialang.org/t/datatype-hash-differs-per-patch-version-and-os/48827/2 "2020-10-22T16:05:26Z")

</div>

This isn’t a bug. Hashing had changed over time for some types to become faster.

---

<div class="post-metadata">

**Author:** ![racinmat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/racinmat/32/11715_2.png) [@racinmat](https://discourse.julialang.org/u/racinmat)\
**Post date:** [October 22, 2020, 4:17pm UTC](https://discourse.julialang.org/t/datatype-hash-differs-per-patch-version-and-os/48827/3 "2020-10-22T16:17:19Z")

</div>

I see, that makes sense. But why is it different per OS?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 22, 2020, 4:38pm UTC](https://discourse.julialang.org/t/datatype-hash-differs-per-patch-version-and-os/48827/4 "2020-10-22T16:38:46Z")

</div>

Oh. I missed that part of it. That might be a bug.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [October 22, 2020, 5:40pm UTC](https://discourse.julialang.org/t/datatype-hash-differs-per-patch-version-and-os/48827/5 "2020-10-22T17:40:42Z")

</div>

A hash is not a checksum. If you require that kind of stability across versions and OS, try `using SHA` and the functions provided by that Base package.

If those functions differ between OS, that’s definitely a bug.

The reaseon `hash(Float32)` differs greatly is because of the way generic hashing is implemented. It falls back to hashing an internal identifier of the object, which can change with each version, different OS and even build from the source code:

```julia
In hash(x) at hashing.jl:18
>18 hash(x::Any) = hash(x, zero(UInt))

About to run: (hash)(Float32, 0x0000000000000000)
1|debug> s
In hash(x, h) at hashing.jl:23
>23 hash(@nospecialize(x), h::UInt) = hash_uint(3h - objectid(x))

"""
    objectid(x)

Get a hash value for `x` based on object identity. `objectid(x)==objectid(y)` if `x === y`.
"""
objectid(@nospecialize(x)) = ccall(:jl_object_id, UInt, (Any,), x)

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [October 22, 2020, 7:32pm UTC](https://discourse.julialang.org/t/datatype-hash-differs-per-patch-version-and-os/48827/6 "2020-10-22T19:32:57Z")

</div>

> [@Sukera](#):
>
> It falls back to hashing an internal identifier of the object, which can change with each version, different OS and even build from the source code:

This is not a reason for the instability. `jl_object_id` **IS** stable for many other types. The hash for datatype changes between build because it was designed to be so (it includes the build time of the module). It’s not a bug but could be made better to reduce build variations but there’s at least currently no guarantee on returning the same value on different builds.

---

<div class="post-metadata">

**Author:** ![racinmat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/racinmat/32/11715_2.png) [@racinmat](https://discourse.julialang.org/u/racinmat)\
**Post date:** [October 23, 2020, 2:52pm UTC](https://discourse.julialang.org/t/datatype-hash-differs-per-patch-version-and-os/48827/7 "2020-10-23T14:52:53Z")

</div>

Oh, so different hash for datatype for windows and linux is because of different build times?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 23, 2020, 3:09pm UTC](https://discourse.julialang.org/t/datatype-hash-differs-per-patch-version-and-os/48827/8 "2020-10-23T15:09:17Z")

</div>

Hashes for Types in general are just object IDs which are essentially arbitrary.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [October 23, 2020, 3:28pm UTC](https://discourse.julialang.org/t/datatype-hash-differs-per-patch-version-and-os/48827/9 "2020-10-23T15:28:55Z")

</div>

They are not any more arbitrary than other types of hash.
