Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing unsafeThaw #66

Open
Qqwy opened this issue Oct 14, 2024 · 2 comments
Open

Missing unsafeThaw #66

Qqwy opened this issue Oct 14, 2024 · 2 comments

Comments

@Qqwy
Copy link

Qqwy commented Oct 14, 2024

I am using Contiguous to implement a new immutable HAMT-style hashmap.
As part of this, I want to provide an unsafeInsert (which is a building block to make other construction functions, like fromList fast).
This, in turn, is built upon unsafeThaw, to mutate the existing immutable arrays in place.

unsafeThaw is supported by the various arrays Contiguous is wrapping, but not yet part of the class.

Would a PR adding it be accepted?

@andrewthad
Copy link
Member

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.

@andrewthad
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants