Skip to content

GHCi command ":set +r" is not working with the bytecode interpreter.

Summary

Normally GHC/GHCi evaluates a Constant Application Form (CAF) only once. However GHCi has a :set +r command to discard the results of a CAF after evaluation, so it should be re-evaluated. This :set +r command is not working in the bytecode interpreter.

The GHC Users-Guide says:

:set +r

Normally, any evaluation of top-level expressions (otherwise known as CAFs or Constant Applicative Forms) in loaded modules is retained between evaluations. Turning on +r causes all evaluation of top-level expressions to be discarded after each evaluation (they are still retained during a single evaluation). This option may help if the evaluated top-level expressions are consuming large amounts of space, or if you need repeatable performance measurements.

Steps to reproduce

With the code

import Debug.Trace

caf :: [Int]
caf = trace "Evaluate!" [1,2,3]

as Foo.hs do:

$ ghci
GHCi, version 8.6.3: http://www.haskell.org/ghc/  :? for help
Loaded package environment from /home/roland/.ghc/x86_64-linux-8.6.3/environments/default
Prelude> :set +r
Prelude> :l Foo.hs
[1 of 1] Compiling Main             ( Foo.hs, interpreted )
Ok, one module loaded.
*Main> caf
Evaluate!
[1,2,3]
*Main> caf
[1,2,3]

Expected behavior

The system should print out the line Evaluate! every time before printing [1,2,3]

Environment

  • GHC version used: 8.6.3 / HEAD
  • Operating System: Linux Debian 9
  • System Architecture: x86_64

Note:

The above bug is only in the bytecode interpreter. It works with the -fobject-code option.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information