Skip to content

hash(::Int, ::UInt) and hash_integer(::Int, ::UInt) no longer coincide #58386

@lgoettgens

Description

@lgoettgens

In Nemo.jl, we introduce a type ZZRingElem to represent a mathematical exact integer of arbitrary size, which is backed by the C-library FLINT. Since we sometimes use these as indices of dictionaries etc., we want everything that fits into an Int64 to hash like that Int64.
This is achieved by querying FLINT if the value consists of just a single limb, and if yes, passing that single limb (as a Int64) together with the h::UInt to Base.hash_integer. This worked fine until #57509 got merged as since then, our nightly CI is splattered with KeyErrors (cf. oscar-system/Oscar.jl#4882).

While digging into this, I noticed that the 2-arg hash and Base.hash_integer used to coincide when the first argument is a Int64, but since #57509 they no longer do.
This can be tested by e.g. hash(17, UInt(0)) == Base.hash_integer(17, UInt(0)).

From the code and previous discussions on github, I wasn't able to conclude if they should coincide (aka #57509 broke something) or if our use of Base.hash_integer assumes too much that just happened to hold by accident.

cc @benlorenz @fingolfin @thofma
ping @adienes @oscardssmith @JeffBezanson

Metadata

Metadata

Assignees

No one assigned

    Labels

    hashingregressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions