Open Qqwy opened 4 weeks ago
Although unsafeThaw
exists as a primop in GHC, it is extremely dangerous. I've only ever seen it used in unordered-containers
to help write fromList
, and even there, I'm skeptical of its soundness.
It's not possibly to make fromList
faster by mutating an immutable array. The existing implementation mutates a mutable array and then freezes it (in place) at the end. Can you describe something in more detail that would benefit from unsafeThaw
? Maybe you do have a way to use unsafeInsert
to make a faster fromList
, but I am not able to see how it could possibly help.
Sorry, I just realized that I missed the first sentence that you wrote. I assume that you're copying the design of unordered-containers. I'll take a PR for unsafeThaw
. I think it should only be available for ContiguousU
types though, not all Countiguous
types.
I am using
Contiguous
to implement a new immutable HAMT-style hashmap. As part of this, I want to provide anunsafeInsert
(which is a building block to make other construction functions, likefromList
fast). This, in turn, is built uponunsafeThaw
, to mutate the existing immutable arrays in place.unsafeThaw
is supported by the various arraysContiguous
is wrapping, but not yet part of the class.Would a PR adding it be accepted?