Skip to content

Core Lint error with -O2 in containers' sequence-benchmarks

I originally reported this in #17722 (comment 248156), but it seems less related to that issue than I initially thought.

From this benchmark I have extracted this reproducer:

{-# language ExistentialQuantification #-}

-- | This code is extracted from containers' sequence-benchmarks and the gauge
-- package.
module M where

import Control.Exception (evaluate)

data Benchmarkable = forall a .
    Benchmarkable
      { allocEnv :: Int -> IO a
      , runRepeatedly :: a -> Int -> IO ()
      }

a, b :: Benchmarkable
a = nf (\(s,t) -> (,) <$> replicate s () <*> replicate t ()) (100,2500)
b = nf (\(s,t) -> (,) <$> replicate s () <*> replicate t ()) (2500,100)

nf :: (a -> b) -> a -> Benchmarkable
nf f0 x0 = Benchmarkable (const (return ())) (const (go f0 x0))
  where go f x n
          | n <= 0    = return ()
          | otherwise = evaluate (f x) >> go f x (n-1)
≻ ~/src/ghc-head/_build/stage1/bin/ghc -dcore-lint T17722-gauge.hs -O2
[1 of 1] Compiling M                ( T17722-gauge.hs, T17722-gauge.o )
*** Core Lint errors : in result of Simplifier ***
<no location info>: warning:
    Out of scope: $wf0_s23v [InlPrag=NOUSERINLINE[2]]
                    :: Int# -> Int -> [((), ())]
                  [LclId, Arity=2, Str=<L,U><L,1*U(U)>]
    In the RHS of $s$wpoly_go_s26H :: State# RealWorld
                                      -> Int# -> (Int, Int) -> (# State# RealWorld, () #)
    In the body of lambda with binder sc_s26z :: State# RealWorld
    In the body of lambda with binder sc_s26y :: Int#
    In the body of lambda with binder sc_s26x :: (Int, Int)
    In a case alternative: ((,) ww_s23o :: Int, ww_s23t :: Int)
    In a case alternative: (I# ww_s23r :: Int#)
    Substitution: [TCvSubst
                     In scope: InScope {x0_X2 f0_aEB x0_aEC $krep_a1TC $krep_a1TD
                                        $krep_a1TE $krep_a1TF $krep_a1TG $krep_a1TH $krep_a1TI
                                        $krep_a1TJ $krep_a1TK $krep_a1TL $krep_a1TM allocEnv
                                        runRepeatedly a b nf $tc'Benchmarkable $tcBenchmarkable
                                        $trModule $trModule_s1Vs $trModule_s1Vt $trModule_s1Vu
                                        $trModule_s1Vv $krep_s1Vw $krep_s1Vx $tcBenchmarkable_s1Vy
                                        $tcBenchmarkable_s1Vz $tc'Benchmarkable_s1VA
                                        $tc'Benchmarkable_s1VB lvl_s1Zp poly_go_s1Zr x0_s1ZN x0_s1ZO
                                        b_s1ZP a_s1ZV lwild_s20a $wpoly_go_s22H $wf0_s236 ww_s23n
                                        ww_s23o ww_s23q ww_s23r ww_s23t go_s256 $wxs_s259 lvl_s25a
                                        sc_s26x sc_s26y sc_s26z $s$wpoly_go_s26H $s$wpoly_go_s26I}
                     Type env: []
                     Co env: []]

Full Core Lint error message

I can reproduce the issue with GHC 8.6.5, 8.8.2, 8.10.1-alpha2 and HEAD (a71323ff), but not with 8.4 and earlier.

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