-
Notifications
You must be signed in to change notification settings - Fork 139
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
Empty storable vectors in GHCi error with divide by zero. #167
Comments
Well, this issue didn't exist in GHC 7.10.3 or earlier by sheer coincidence. The reason it changed in 8.0 is that a new instance Storable () where
sizeOf _ = 0
alignment _ = 1
peek _ = return ()
poke _ _ = return () And luck just has it that if you type |
A quick search reveals this as a likely culprit: instance Storable a => G.MVector MVector a where
...
basicUnsafeNew n
| n < 0 = error $ "Storable.basicUnsafeNew: negative length: " ++ show n
| n > mx = error $ "Storable.basicUnsafeNew: length too large: " ++ show n
| otherwise = unsafePrimToPrim $ do
fp <- mallocVector n
return $ MVector n fp
where
size = sizeOf (undefined :: a)
mx = maxBound `quot` size :: Int |
Makes sense and indeed that seems to be the culprit. Now, for solution, the simplest way would be to disallow making a storable vector of |
I think there's a preexisting ticket about handling zero width storable
values.
Making them erroneous probably isn't the right approach ...
…On Sun, Apr 30, 2017 at 9:57 PM Mihai Maruseac ***@***.***> wrote:
Makes sense and indeed that seems to be the culprit.
Now, for solution, the simplest way would be to disallow making a storable
vector of (). At least this will give educative error messages. I made
#168 <#168> for this, as a starting
point.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#167 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAQwklKu6VUkS2OGNyQrIeIY20s24nQks5r1TvqgaJpZM4NMuYD>
.
|
Yeah, it's issue #105 (I only searched for it now). I see that no progress has been made on it :( I changed my PR so now it divides by 1 if the size of the elements is 0. |
Compiled the following with profiling import qualified Data.Vector.Storable as VS
main = print (VS.empty :: VS.Vector ()) and indeed got the expected error *** Exception (reporting due to +RTS -xc): (THUNK_STATIC), stack trace:
GHC.Real.CAF
--> evaluated by: Data.Vector.Storable.Mutable.basicUnsafeNew,
called from Main.main,
called from Main.CAF:main3
--> evaluated by: Main.main,
called from Main.CAF:main2
--> evaluated by: Main.main
mm: divide by zero The error goes away with fix I proposed in #168 |
Fix merged. |
In GHCi:
Enabling
-XNoMonomorphismRestriction
, giving it an explicit type or having it compiled byghc
from a file makes the error go away.This doesn't happen for either boxed (
Data.Vector
) or unboxed (Data.Vector.Unboxed
) vectors.I consider it a
vector
bug since it's an inconsistency between the unboxed and the storable case. But, if it is not, feel free to close this/raise it to the proper bug tracker.The text was updated successfully, but these errors were encountered: