Skip to content

environment-changing function for a ReaderT variant exhausts simplifier ticks

Summary

A variant of the ReaderT monad for which the environment is parameterized with the monad itself fails to compile.

More precisely, a function (zoomEnv) that changes an environment parameterized by the monad fails to compile with a "Simplifier ticks exhausted" error.

Simplifier ticks exhausted
  When trying UnfoldingDone ds_s1x3
  To increase the limit, use -fsimpl-tick-factor=N (default 100).

Increasing the limit doesn't make it compile.

Putting a NOINLINE pragma on zoomEnv makes it compile correctly.

The datatype is defined as follows:

type DepT ::
  ((Type -> Type) -> Type) ->
  (Type -> Type) ->
  Type ->
  Type
newtype DepT env m r = DepT {toReaderT :: ReaderT (env (DepT env m)) m r}

Looking at the "Known bugs and infelicities" section of the GHC User Guide, it looks somewhat similar to this known infelicity-causing code:

data U = MkU (U -> Bool)

russel :: U -> Bool
russel u@(MkU p) = not $ p u

x :: Bool
x = russel (MkU russel)

The similarity lies in that DepT receives an environment as parameter, and that environment usually will have occurrences of DepT itself in "positive position".

I wasn't completely sure that it's really the same situation though, so I've opened the bug.

Steps to reproduce

Compile the attached file Main.hs with ghc -O2.

The program will compile correctly with ghc -O0.

Expected behavior

The program should compile with ghc -O2.

Environment

  • GHC version used: 8.10.3
  • Operating System: Windows 10
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information