Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation time and GHC's fsimpl-tick-factor #112

Open
YPares opened this issue Mar 2, 2018 · 6 comments
Open

Compilation time and GHC's fsimpl-tick-factor #112

YPares opened this issue Mar 2, 2018 · 6 comments

Comments

@YPares
Copy link

YPares commented Mar 2, 2018

Hi! When using vinyl with a decent amount of record manipulation I'm getting:

ghc: panic! (the 'impossible' happened)
  (GHC version 8.2.2 for x86_64-unknown-linux):
	Simplifier ticks exhausted
  When trying RuleFired Class op $p1RElem
  To increase the limit, use -fsimpl-tick-factor=N (default 100)
  If you need to do this, let GHC HQ know, and what factor you needed
  To see detailed counts use -ddump-simpl-stats
  Total ticks: 445800
  Call stack:
      CallStack (from HasCallStack):
        prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1133:58 in ghc:Outputable
        callStackDoc, called at compiler/utils/Outputable.hs:1137:37 in ghc:Outputable
        pprPanic, called at compiler/simplCore/SimplMonad.hs:199:31 in ghc:SimplMonad

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Indeed, running it with -fsimpl-tick-factor=200 makes it build. However the build remains very slow (over 2mn for one file). It specifically is slow when I try to make record subtraction :

type family LProduct a b where
   LProduct '[] b = '[]
   LProduct (a:as) b = '(a,b) : LProduct as b

type family Difference_ a where
   Difference_ '[] = '[]
   Difference_ ( '(a,'[]) : rest )  = a : Difference_ rest
   Difference_ ( '(a,a:bs) : rest ) = Difference_ rest
   Difference_ ( '(a,b:bs) : rest ) = Difference_ ( '(a,bs) : rest )

type Difference a b = Difference_ (LProduct a b)

This is coded this way to avoid a need for UndecidableInstances (which makes compilation time even longer). Is there a way to alleviate the tweaking of simpl-tick-factor or speed up compilation?

@acowley
Copy link
Contributor

acowley commented Mar 2, 2018

I'm afraid I don't know of any easy solutions to this. It might be interesting to see if using Data.Singletons.Prelude.List.(\\) works better.

@YPares
Copy link
Author

YPares commented Mar 2, 2018

I'm not exactly sure of how to use promoted TFs from singletons...

Couldn't match type ‘Data.Singletons.Prelude.List.DeleteBy
                             (Data.Singletons.Prelude.Eq.:==$)
                             '("field1", Int)
                             (Data.Singletons.Prelude.List.DeleteBy
   ...

It doesn't seem to produce a GHC literal type-level list. Does it?

@abooij
Copy link

abooij commented Mar 2, 2018

I'd be very interested in a minimal working example!

@acowley
Copy link
Contributor

acowley commented Mar 2, 2018

Huh, I don't know how to use them either. In GHCi,

> :kind! ('[String, Int] :\\ '[String])
('[String, Int] :\\ '[String]) :: [*]
= Data.Singletons.Prelude.List.Case_6989586621679726864
    (Data.Singletons.Prelude.Eq.:==$)
    [Char]
    [Char]
    '[Int]
    ([Char] Data.Singletons.Prelude.Eq.:== [Char])

And if I ask if that's the same as '[Int], I get a type error. That doesn't seem very helpful.

@YPares
Copy link
Author

YPares commented Mar 5, 2018

@acowley From what I gather in https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/using-optimisation.html#ghc-flag--fsimpl-tick-factor=%E2%9F%A8n%E2%9F%A9
this is due to either inlining or rewrite rules. This is not the typechecking phase that's taking ages. And that's coherent with what I observe when using my file with intero/ghci. Here, the typechecking finishes quickly and no rewrite rules are triggered

Do you have an idea of which rewrite rules are triggered here and if that's possible to deactivate them? I'd like not to have to build my file with -O0 and deactivate all optimization...
EDIT: I checked, and building with -O0 indeed makes it build normally

@YPares
Copy link
Author

YPares commented Mar 5, 2018

It's weird because the error mentions " When trying RuleFired Class op $p1RElem" but there are no rewrite rules in vinyl...

With ddump-simpl-stats I see:

  384051 RuleFired
    246073 Class op HEq_sc
    123043 Class op $p1RElem
    6402 Class op $p1RSubset
    4130 Class op fmap
    3568 Class op rlens
    271 Class op rput
    271 Class op rreplace
    62 Class op showPathList
    38 Class op rcast
    34 Class op rget
    24 Class op basicLength
    24 Class op return
    18 Class op $p1PrimMonad
    18 Class op >>=
    18 Class op primitive
    12 Class op $p1Vector
    12 Class op >>
    6 +#
    6 Class op basicUnsafeGrow
    6 Class op basicUnsafeSlice
    6 Class op basicUnsafeWrite
    4 tagToEnum#
    2 SPEC/BioModels.Helpers.ModelCLI $wlookupInArray @ Text _
    2 SPEC/BioModels.Helpers.ModelCLI $wupdateOrSnocWithKey @ Text _
    1 Class op rsubset

We see indeed a LOT of firing of rule $p1RElem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants