[英]GHC crashes while compiling
module Main where
newtype Rec a b = Rec {deRec :: Rec a b -> a}
infixl 1 >|>
infixl 1 <|<
(>|>) = Rec
(<|<) (Rec x) = x
fix f = (\x -> f (x <|< x)) (Rec (\x -> f (x <|< x)))
factorial = fix (\f x -> if x<=1 then 1 else x*f(x-1))
main = do
x <- getLine
putStrLn (show (factorial (read x)))
GHC回應:
ghc: panic! (the 'impossible' happened)
(GHC version 7.6.3 for x86_64-apple-darwin):
Simplifier ticks exhausted
When trying UnfoldingDone a_sMx{v} [lid]
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: 7121
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
怎么了?
我認為這與已知的bug有關。 參見ghc
手冊的14.2節:
http://www.haskell.org/ghc/docs/7.6.2/html/users_guide/bugs.html
我將在這里重現相關部分:
使用標准方法通過數據類型編碼遞歸,可以將GHC的inliner說服為非終止:
data U = MkU (U -> Bool)
russel :: U -> Bool
russel u@(MkU p) = not $ p u
x :: Bool
x = russel (MkU russel)
我們從來沒有發現過另一類程序,除了這個程序之外,它使GHC發散,修復問題會給每次編譯帶來額外的開銷。 所以bug仍然是不固定的。 GHC內襯的秘密有更多背景。
換句話說,當您在負位置(即函數的參數)使用遞歸時會出現此錯誤。 從手冊中可以看出,他們無意解決這個問題。
正如前面提到的那樣,當GHC內聯使用具有遞歸類型參數的函數時,會出現問題。 這可以與NOINLINE
pragma一起使用。 在你的情況下:
{-# NOINLINE (<|<) #-}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.