Skip to content

Something is wrong with LBS.ByteString literals #393

@phadej

Description

@phadej

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions