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

This package does not build with GHC 9.4.8. #6

Open
kindaro opened this issue May 11, 2024 · 1 comment
Open

This package does not build with GHC 9.4.8. #6

kindaro opened this issue May 11, 2024 · 1 comment

Comments

@kindaro
Copy link

kindaro commented May 11, 2024

what I do

% git remote -v
origin	https://github.com/pxqr/base32-bytestring.git (fetch)
origin	https://github.com/pxqr/base32-bytestring.git (push)
% git rev-parse @
3a6fe39aa734fd053baababdc8afa413999c8cd1
% ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.4.8
% cabal build
Build profile: -w ghc-9.4.8 -O1
In order, the following will be built (use -v for more details):
 - base32-bytestring-0.2.1.0 (lib) (first run)
Preprocessing library for base32-bytestring-0.2.1.0..
Building library for base32-bytestring-0.2.1.0..
[1 of 3] Compiling Data.ByteString.Base32.Internal ( src/Data/ByteString/Base32/Internal.hs, /tmp/base32-bytestring/dist-newstyle/build/x86_64-linux/ghc-9.4.8/base32-bytestring-0.2.1.0/build/Data/ByteString/Base32/Internal.o, /tmp/base32-bytestring/dist-newstyle/build/x86_64-linux/ghc-9.4.8/base32-bytestring-0.2.1.0/build/Data/ByteString/Base32/Internal.dyn_o )

src/Data/ByteString/Base32/Internal.hs:73:1: error:
    Parse error in pattern: unpack5Ptr In a function binding for the ‘@’ operator.
                            Perhaps you meant an as-pattern, which must not be surrounded by whitespace
   |
73 | unpack5Ptr !tbl bs @ (PS fptr off sz) =
   | ^^^^^^^^^^^^^^^^^^
Error: cabal: Failed to build base32-bytestring-0.2.1.0.

what should happen

Running cabal build should build the package.

discussion

The reason for this error is that the parsing of @ has become white space sensitive, I think since the proposal ghc-proposals/ghc-proposals#229, so in this case white space about the @ needs to be cut away.

@kindaro
Copy link
Author

kindaro commented May 11, 2024

After removing the white space about all @ characters and replacing inlinePerformIO with unsafePerformIO, I have this package build. Here is the patch:

diff --git a/src/Data/ByteString/Base32/Internal.hs b/src/Data/ByteString/Base32/Internal.hs
index aa7c5b3..29a9720 100644
--- a/src/Data/ByteString/Base32/Internal.hs
+++ b/src/Data/ByteString/Base32/Internal.hs
@@ -70,7 +70,7 @@ padCeilN !n !x
 -----------------------------------------------------------------------}

 unpack5Ptr :: Ptr Word8 -> ByteString -> ByteString
-unpack5Ptr !tbl bs @ (PS fptr off sz) =
+unpack5Ptr !tbl bs@(PS fptr off sz) =
   unsafePerformIO $ do
     let unpackedSize = dstSize $ BS.length bs
     BS.create unpackedSize $ \ dst -> do
@@ -164,7 +164,7 @@ cleanup io = unsafePerformIO $
     handler (ErrorCall msg) = return (Left msg)

 pack5Ptr :: Ptr Word5 -> ByteString -> Result ByteString
-pack5Ptr !tbl bs @ (PS fptr off sz) =
+pack5Ptr !tbl bs@(PS fptr off sz) =
   cleanup $ do
     let packedSize = dstSize $ BS.length bs
     BS.createAndTrim packedSize $ \ dst -> do
@@ -176,7 +176,7 @@ pack5Ptr !tbl bs @ (PS fptr off sz) =
     lookupTable ix
         | x == invIx = error $ show (w2c ix) ++ " is not base32 character"
         | otherwise  = x
-      where x = inlinePerformIO (peekByteOff tbl (fromIntegral ix))
+      where x = unsafePerformIO (peekByteOff tbl (fromIntegral ix))
     {-# INLINE lookupTable #-}

     dstSize x = d + if m == 0 then 0 else 1
@@ -248,10 +248,10 @@ pack5 (PS fptr off len) bs

 isInAlphabet :: Ptr Word5 -> Word8 -> Bool
 isInAlphabet !tbl !ix =
-  inlinePerformIO (peekByteOff tbl (fromIntegral ix)) /= invIx
+  unsafePerformIO (peekByteOff tbl (fromIntegral ix)) /= invIx

 pack5Lenient :: DecTable -> ByteString -> Either String ByteString
-pack5Lenient tbl @ (PS fptr _ _) bs =
+pack5Lenient tbl@(PS fptr _ _) bs =
   unsafePerformIO $ do
     withForeignPtr fptr $ \ !tbl_ptr -> do
       return $! pack5 tbl $ BS.filter (isInAlphabet tbl_ptr) bs

I have not checked if the package works as it should though.

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

1 participant