Skip to content

:sprint in GHCi yields surprising results on BCOs linked as a group

Summary

When two bindings are defined in the same binding group their thunks will not update correctly.

Steps to reproduce

GHCi, version 9.6.2: https://www.haskell.org/ghc/  :? for help
ghci> :{
ghci| y = 1 + 2 + 3 :: Int
ghci| x = (y, y)
ghci| :}
ghci> :force y
y = 6
ghci> :sprint x
x = _

Notes:

  • :force is not necessary, forcing y by printing it also does not update x.

  • ; instead of the multiline :{ :} block also exhibits the same bad behaviour.

  • Loading the x and y bindings from a file exhibits the same issue.

  • You could argue that x itself simply hasn't evaluated the outer (,) constructor yet, but that doesn't explain this:

    ghci> x = 1 + 2 :: Int; y = [x, x]
    ghci> length y
    2
    ghci> :force x
    x = 3
    ghci> :sprint y
    y = [_,_]
  • performMajorGC does not change anything.

Expected behavior

It should behave the same as two separate bindings:

ghci> y = 1 + 2 + 3 :: Int
ghci> x = (y, y)
ghci> :force y
y = 6
ghci> :sprint x
x = (6,6)

Environment

  • GHC version used: 9.6.2
Edited by Jaro Reinders
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information