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 NFData instances for unboxed arrays #8

Open
meooow25 opened this issue Sep 8, 2024 · 6 comments
Open

Missing NFData instances for unboxed arrays #8

meooow25 opened this issue Sep 8, 2024 · 6 comments

Comments

@meooow25
Copy link
Contributor

meooow25 commented Sep 8, 2024

NFData instances for unboxed arrays (UArray, STUArray, IOUArray, StorableArray) are currently missing.

Ideally, they would be defined here, but we can't do that because deepseq (which defines NFData) depends on array.
However, deepseq has agreed to drop this dependency (see haskell/deepseq#102), which makes this possible in the future.

For array, this would mean:

  1. Wait for a new deepseq release which does not depend on array
  2. Depend on deepseq and define the instances.

Does this sound ok to the maintainers here?

@July541
Copy link
Contributor

July541 commented Sep 8, 2024

Thanks for your work!
I wonder if it has any affection on the ghc side since array is the package ghc dependency.

@July541
Copy link
Contributor

July541 commented Sep 8, 2024

The latest deepseq supports base from 4.12-4.20, and array supports base from 4.9-4.20, which means we have to drop support before base-4.12(ghc-8.6) in the future release.

@Bodigrim
Copy link

Bodigrim commented Sep 8, 2024

I wonder if it has any affection on the ghc side since array is the package ghc dependency.

ghc-the-package depends on deepseq directly, so I would not expect any complications.

we have to drop support before base-4.12(ghc-8.6) in the future release.

I think it's reasonable, pretty much every other core package has done it already.

@meooow25
Copy link
Contributor Author

meooow25 commented Sep 8, 2024

The latest deepseq supports base from 4.12-4.20, and array supports base from 4.9-4.20, which means we have to drop support before base-4.12(ghc-8.6) in the future release.

That's a good point. If you have reasons to keep supporting older base, this will have to wait.

@July541
Copy link
Contributor

July541 commented Nov 3, 2024

I'd like to implement this for the next coming release, but not sure if rnf = rwhnf is enough for unboxed arrays since I don't have a counterexample:(

@meooow25
Copy link
Contributor Author

meooow25 commented Nov 3, 2024

There is no need to force the data for unboxed arrays but we should force the stored index. For example,

instance NFData i => NFData (STUArray s i e) where
  rnf (STUArray l u _ _) = rnf l `seq` rnf u

On a related note, it seems StorableArray is lazy in the Int number of elements, I can't imagine why.

data StorableArray i e = StorableArray !i !i Int !(ForeignPtr e)

Probably it should be made strict.

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

3 participants