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

Something is wrong with LBS.ByteString literals #393

Closed
phadej opened this issue May 22, 2021 · 2 comments
Closed

Something is wrong with LBS.ByteString literals #393

phadej opened this issue May 22, 2021 · 2 comments

Comments

@phadej
Copy link
Contributor

phadej commented May 22, 2021

See #392 for discovery.

By reducing test case to, which can be built with master:

{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where

import           Test.Tasty (defaultMain, testGroup)
import           Test.Tasty.HUnit (testCase, (@=?))
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS

main :: IO ()
main = defaultMain $ testGroup "bytestring-th"
  [ testGroup "lazy"
    [ testCase "binary" $ do
        let bs :: LBS.ByteString
            bs = "\0\1"


        bs @=? LBS.pack [0,1]

    ]
  ]

The Core with GHC-9.0.1 has terms:

-- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0}
lvl1_r5QU :: ghc-prim-0.7.0:GHC.Prim.Addr#
[GblId, Unf=OtherCon []]
lvl1_r5QU = "\\128\SOH"#

-- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0}
lvl2_r5QV :: [Char]
[GblId]
lvl2_r5QV = ghc-prim-0.7.0:GHC.CString.unpackCStringUtf8# lvl1_r5QU
ghci> unpackCStringUtf8# "\128\SOH"#
"\-4223"
ghci> (-4223) `mod` 256
129

which explain where from 129 comes from. But how those Core terms are generated, I don't know.

This happens with GHC-9.0 and GHC-9.2.0.20210422, but doesn't with GHC-8.x


cc @bgamari

@phadej
Copy link
Contributor Author

phadej commented May 22, 2021

Another data point. If I run script:

{- cabal:
build-depends: tasty, tasty-hunit, base, bytestring
-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where

import           Test.Tasty (defaultMain, testGroup)
import           Test.Tasty.HUnit (testCase, (@=?))
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS

main :: IO ()
main = defaultMain $ testGroup "bytestring-th"
  [ testGroup "lazy"
    [ testCase "binary" $ do
        let bs :: LBS.ByteString
            bs = "\0\1"

        bs @=? LBS.pack [0,1]

    ]
  ]

with cabal run test-case.hs -w ghc-9.0.1 then it is fine, but

% cabal run test-case.hs -w ghc-9.2.0.20210422
Warning: Unknown/unsupported 'ghc' version detected (Cabal 3.4.0.0 supports
'ghc' version < 9.1): /opt/ghc/bin/ghc-9.2.0.20210422 is version
9.2.0.20210422
Resolving dependencies...
...

[1 of 1] Compiling Main             ( Main.hs, /tmp/cabal-repl.-128098/dist-newstyle/build/x86_64-linux/ghc-9.2.0.20210422/fake-package-0/x/script/build/script/script-tmp/Main.o )
Linking /tmp/cabal-repl.-128098/dist-newstyle/build/x86_64-linux/ghc-9.2.0.20210422/fake-package-0/x/script/build/script/script ...
bytestring-th
  lazy
    binary: FAIL
      Main.hs:20:
      expected: "\NUL\129"
       but got: "\NUL\SOH"

fails. So it looks that some recent change in bytestring triggers the issue.

@phadej phadej mentioned this issue May 22, 2021
phadej added a commit to phadej/bytestring that referenced this issue May 24, 2021
phadej added a commit to phadej/bytestring that referenced this issue May 24, 2021
Bodigrim pushed a commit that referenced this issue May 31, 2021
Bodigrim pushed a commit to Bodigrim/bytestring that referenced this issue Jun 10, 2021
@phadej
Copy link
Contributor Author

phadej commented Jun 24, 2021

This issue was GHC one, and now it's fixed.

@phadej phadej closed this as completed Jun 24, 2021
noughtmare pushed a commit to noughtmare/bytestring that referenced this issue Dec 12, 2021
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