hedgehogqa / hedgehogqa/haskell-hedgehog-classes

storableLaws/storablePeekByte shouldn't expect every element of an array via `newArray` to be aligned?

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

Description

https://github.com/hedgehogqa/haskell-hedgehog-classes/blob/69212627dca7b21252a55495299e9bb84434d2ac/src/Hedgehog/Classes/Storable.hs#L76-L87

In the implementation of `storablePeekByte`, every element's offset into the array is aligned to the `Storable` instance's supplied alignment.

However, this is not how GHC actually writes Storable arrays. That's how *I* thought alignment would be treated as well -- that each element of an array would be aligned. That does not seem to be the case, at least in GHC functions like `newArray`, `pokeArray`, etc. -- see https://gitlab.haskell.org/ghc/ghc/-/blob/dbd852f5dc641ae4f41ac242e394f9b68587e701/libraries/ghc-internal/src/GHC/Internal/Foreign/Marshal/Array.hs#L176 -- they all seem to write array elements as compactly as possible. Functions like `allocaArray` use alignment to align the address of the array itself but say nothing of the elements.

For comparison, quickcheck-classes implementation of the storablePeekByte property does not align every element offset.

https://github.com/andrewthad/quickcheck-classes/blob/ecd8ceb1c30a23d7edbe4af552bdc4be6274b773/quickcheck-classes-base/src/Test/QuickCheck/Classes/Storable.hs#L62-L70

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with src/Hedgehog/Classes/Storable.hs lines 76-87 and inspect how storablePeekByte calculates array element offsets. Compare that behavior with the linked GHC array implementation and the quickcheck-classes property. Done means the property reflects GHC's compact array layout rather than aligning every element individually.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.