【问题标题】:Is this a GHC bug?这是 GHC 错误吗?
【发布时间】:2014-04-15 17:59:59
【问题描述】:

我有以下程序,它不会编译;它只是卡在 Compiling Main 上。我不确定它为什么会冻结,因为它要么是错误,要么是我遗漏了什么?

import qualified Data.Vector.Unboxed as V

test :: [Int]
test = V.foldl' unique [] k
 where 
    n = 10000000
    k = V.generate n (\i -> i `div` 1000 * 1000)
    unique [] k = [k]
    unique acc@(ck:_) k
        | k == ck = acc
        | otherwise = k:acc     

main :: IO ()
main = print $ head test

ghc --make -O3 -Odph -fllvm test.hs

【问题讨论】:

  • 如果编译器挂起,这显然是编译器错误,或者环境有问题(或者您正在使用 C++ 进行元编程)。
  • 在编译的哪个阶段挂起?您可以告诉 GHC 在特定阶段后停止,您可以转储 Core,还是卡在其他地方?
  • 看起来很奇怪,但这是为我编译的ghc --make test.hs
  • @mydogisbox 声称 C++ 是唯一允许编译器循环的语言似乎有点自大,不是吗? GHC 具有允许您在编译时编写和评估类型级循环的扩展,以及允许您在编译时编写和评估任意 Haskell 代码的扩展。没有先验理由认为 GHC 不可能同时正常运行并永远循环。
  • @DanielWagner 要么我在开玩笑。你永远不会知道是哪个!我承认我不知道 GHC 允许元编程扩展。

标签: haskell ghc


【解决方案1】:

是的,我认为这是错误:https://ghc.haskell.org/trac/ghc/ticket/5550

使用-v,可以看到在进行SpecConstr优化时GHC挂起:

ghc-7.6.3 test.hs -O2 -fforce-recomp -v
Glasgow Haskell Compiler, Version 7.6.3, stage 2 booted by GHC version 7.0.4
Using binary package database: /nix/store/x5rdp4smhc6q3rxbw4x1akj10z3h0lvg-haskell-env-ghc-7.6.3/lib/ghc-7.6.3/package.conf.d/package.cache
hiding package Cabal-1.16.0 to avoid conflict with later version Cabal-1.18.1.3
hiding package QuickCheck-2.6 to avoid conflict with later version QuickCheck-2.7.3
hiding package binary-0.5.1.1 to avoid conflict with later version binary-0.7.1.0
wired-in package ghc-prim mapped to ghc-prim-0.3.0.0-d5221a8c8a269b66ab9a07bdc23317dd
wired-in package integer-gmp mapped to integer-gmp-0.5.0.0-2f15426f5b53fe4c6490832f9b20d8d7
wired-in package base mapped to base-4.6.0.1-02ac91ff7de681afee6a8fa62f0c87f3
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-2.8.0.0-0cee70fbb279a3d93dcc4ec502790a2b
wired-in package dph-seq not found.
wired-in package dph-par not found.
Hsc static flags: -static
*** Chasing dependencies:
Chasing modules from: *test.hs
Stable obj: []
Stable BCO: []
Ready for upsweep
  [NONREC
      ModSummary {
         ms_hs_date = 2014-04-15 18:43:29 UTC
         ms_mod = main:Main,
         ms_textual_imps = [import (implicit) Prelude,
                            import qualified Data.Vector.Unboxed as V]
         ms_srcimps = []
      }]
*** Deleting temp files:
Deleting: 
compile: input file test.hs
Created temporary directory: /tmp/ghc23870_0
*** Checking old interface for main:Main:
[1 of 1] Compiling Main             ( test.hs, test.o )
*** Parser:
*** Renamer/typechecker:
*** Desugar:
Result size of Desugar (after optimization)
  = {terms: 55, types: 44, coercions: 0}
*** Simplifier:
Result size of Simplifier iteration=1
  = {terms: 46, types: 34, coercions: 5}
Result size of Simplifier iteration=2
  = {terms: 48, types: 40, coercions: 5}
Result size of Simplifier = {terms: 48, types: 40, coercions: 5}
*** Specialise:
Result size of Specialise = {terms: 48, types: 40, coercions: 5}
*** Float out(FOS {Lam = Just 0, Consts = True, PAPs = False}):
Result size of Float out(FOS {Lam = Just 0,
                              Consts = True,
                              PAPs = False})
  = {terms: 66, types: 58, coercions: 5}
*** Float inwards:
Result size of Float inwards = {terms: 66, types: 58, coercions: 5}
*** Simplifier:
Result size of Simplifier iteration=1
  = {terms: 76, types: 66, coercions: 36}
Result size of Simplifier iteration=2
  = {terms: 71, types: 60, coercions: 26}
Result size of Simplifier = {terms: 71, types: 60, coercions: 26}
*** Simplifier:
Result size of Simplifier iteration=1
  = {terms: 143, types: 113, coercions: 33}
Result size of Simplifier iteration=2
  = {terms: 99, types: 79, coercions: 30}
Result size of Simplifier = {terms: 99, types: 79, coercions: 30}
*** Simplifier:
Result size of Simplifier iteration=1
  = {terms: 120, types: 88, coercions: 26}
Result size of Simplifier iteration=2
  = {terms: 90, types: 64, coercions: 16}
Result size of Simplifier iteration=3
  = {terms: 88, types: 63, coercions: 16}
Result size of Simplifier = {terms: 88, types: 63, coercions: 16}
*** Demand analysis:
Result size of Demand analysis
  = {terms: 88, types: 63, coercions: 16}
*** Worker Wrapper binds:
Result size of Worker Wrapper binds
  = {terms: 108, types: 80, coercions: 23}
*** Simplifier:
Result size of Simplifier iteration=1
  = {terms: 100, types: 72, coercions: 13}
Result size of Simplifier iteration=2
  = {terms: 91, types: 58, coercions: 9}
Result size of Simplifier = {terms: 91, types: 58, coercions: 9}
*** Float out(FOS {Lam = Just 0, Consts = True, PAPs = True}):
Result size of Float out(FOS {Lam = Just 0,
                              Consts = True,
                              PAPs = True})
  = {terms: 93, types: 59, coercions: 9}
*** Common sub-expression:
Result size of Common sub-expression
  = {terms: 93, types: 59, coercions: 9}
*** Float inwards:
Result size of Float inwards = {terms: 93, types: 59, coercions: 9}
*** Liberate case:
Result size of Liberate case = {terms: 93, types: 59, coercions: 9}
*** Simplifier:
Result size of Simplifier iteration=1
  = {terms: 93, types: 59, coercions: 9}
Result size of Simplifier = {terms: 93, types: 59, coercions: 9}
*** SpecConstr:
Result size of SpecConstr

您还可以测试使用-fno-spec-constr-fno-enable-rewrite-rules 使错误消失。它使用最新的 GHC (7.8.2) 对其进行了测试,问题似乎已经解决。

【讨论】:

    猜你喜欢
    • 2012-07-24
    • 2012-03-18
    • 2015-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    相关资源
    最近更新 更多