ekmett / ekmett/intern

Uniqueness guarantees broken in case of overflow? Or document why not

Open
#8 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
25
Forks
8
PR merge metrics
No merged PRs in 30d

Description

When writing docs (#2), I reverse-engineered from examples (`Term`) that two entries with the same IDs should be equal. However, what happens if `cacheWidth * i` below overflows an integer? This seems unlikely, but also next to impossible to track down if it ever actually happens.

However, I suppose you have some good reason to assume it won't overflow. Are there any caveats?

``` haskell
intern :: Interned t => Uninterned t -> t
intern !bt = unsafeDupablePerformIO $ modifyAdvice $ atomicModifyIORef slot go
where
slot = getCache cache ! r
!dt = describe bt
!hdt = hash dt
!wid = cacheWidth dt
r = hdt `mod` wid
go (CacheState i m) = case HashMap.lookup dt m of
Nothing -> let t = identify (wid * i + r) bt in (CacheState (i + 1) (HashMap.insert dt t m), t)
Just t -> (CacheState i m, t)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.