ekmett / stable-maps

Heterogeneous collections indexed by StableNames
http://github.com/ekmett/stable-maps
BSD 3-Clause "New" or "Revised" License
5 stars 3 forks source link

We still have a (big) safety problem #10

Open treeowl opened 6 years ago

treeowl commented 6 years ago

Suppose we have

x :: Either Int Char
x = Right 'a'

y :: Either Bool Char
y = Right 'a'

Thanks to some CMM-level optimizations, it is possible that x and y will live at the same address. I can insert (x, Identity (Left 3)) into the map, then perform a lookup with y and get something utterly wrong.

treeowl commented 6 years ago

I think this means we should only have the Typeable version and the dynamic version. What say you?

ekmett commented 6 years ago

I'm sad, but feel free to make it so.

treeowl commented 6 years ago

There are two options: we can either use the Typed version as the default, or one with different insertion behavior. The other option is for a key to replace an existing one with the same stable name but a different type.