簡體   English   中英

Haskell GHCI沒有加載編譯對象文件

[英]Haskell GHCI not loading compiled object file

我希望GHCI加載一個模塊的編譯對象代碼,該模塊在編譯時明顯快於無編譯版本。 當所有文件都在同一目錄(沒有模塊層次結構)時,這很有效。 但是,當文件位於模塊層次結構中時,它們不起作用。

工作版MyFile.hs:

import Basic
import Histogram

其中Basic.o和Histogram.o與MyFile.hs在同一目錄中

不工作的版本MyFile.hs:

import Util.Basic
import Util.Histogram

其中Basic.o和Histogram.o位於子目錄Util中。 使用此版本,我在加載MyFile.hs時得到以下內容:

[1 of 2] Compiling Util.Basic ( Util/Basic.hs, interpreted )
[2 of 2] Compiling Util.Histogram ( Util/Histogram.hs, interpreted )
Ok, modules loaded: Util.Basic, Util.Histogram.

我希望能夠在模塊中組織我的代碼,但仍然可以從使用編譯的o文件中獲益。

此外,應該注意的是,自編譯o文件以來,源文件尚未更改。

編輯:以下是每個文件的內容:

MyFile.hs

import Util.Basic
import Util.Histogram

UTIL / Basic.hs

module Util.Basic () where

UTIL / Histogram.hs

module Util.Histogram () where

文件/編譯:

$:~/programming/haskell/example-error$ ls
MyFile.hs  MyFile.hs~  Util
$:~/programming/haskell/example-error$ cd Util
$:~/programming/haskell/example-error/Util$ ls
Basic.hs  Basic.hs~  Histogram.hs  Histogram.hs~
$:~/programming/haskell/example-error/Util$ ghc *.hs
[1 of 2] Compiling Util.Histogram   ( Histogram.hs, Histogram.o )
[2 of 2] Compiling Util.Basic       ( Basic.hs, Basic.o )
$:~/programming/haskell/example-error/Util$ ls
Basic.hi  Basic.hs~  Histogram.hi  Histogram.hs~
Basic.hs  Basic.o    Histogram.hs  Histogram.o
$:~/programming/haskell/example-error/Util$  cd ../
$:~/programming/haskell/example-error$ ghci -ignore-dot-ghci MyFile.hs
GHCi, version 7.4.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 3] Compiling Util.Histogram   ( Util/Histogram.hs, interpreted )
[2 of 3] Compiling Util.Basic       ( Util/Basic.hs, interpreted )
[3 of 3] Compiling Main             ( MyFile.hs, interpreted )
Ok, modules loaded: Util.Basic, Util.Histogram, Main.
*Main> 

丹尼爾建議的解決方案:

The fix is to compile the importing file, and the files in the 
subdirectory only as a consequence of that, not directly. 

問題與下面討論的相同,標志發生了變化:

~/.../Util> ghc Other.hs
[1 of 1] Compiling Util.Other       ( Other.hs, Other.o )
~/.../Util> cd ..
~/.../src> ghc MyFile.hs
[1 of 2] Compiling Util.Other       ( Util/Other.hs, Util/Other.o ) [flags changed]
[2 of 2] Compiling MyFile           ( MyFile.hs, MyFile.o )

我沒有找到特別的標志,或者為什么在單獨編譯期間傳遞的標志與從編譯作為從導入模塊追逐的模塊時傳遞的標志不同,但是它們確實發生了變化,因此需要重新編譯(具體來說, .hi文件中的標志哈希值會發生變化)。

因此,修復程序不是單獨編譯模塊,而是將它們編譯為頂級導入程序的依賴項。


原來幾乎正確的猜測:

我只能部分重現這一點。 編譯完成后再touch MyFile.hs

$ ghci-7.4.2 MyFile.hs
-- snip
[1 of 2] Compiling Util.Other       ( Util/Other.hs, interpreted )
[2 of 2] Compiling MyFile           ( MyFile.hs, interpreted )
Ok, modules loaded: MyFile, Util.Other.

它看起來和你一樣,但是對於7.6.1,我們得到一個提示(編譯和touch ):

$ ghci MyFile.hs
-- snip
[1 of 2] Compiling Util.Other       ( Util/Other.hs, interpreted ) [flags changed]
[2 of 2] Compiling MyFile           ( MyFile.hs, interpreted )
Ok, modules loaded: MyFile, Util.Other.

標志改變了。 我有:set -XNoMonomorphismRestriction在我的.ghci文件中:set -XNoMonomorphismRestriction ,並且標志的更改會導致重新編譯。

$ ghci -ignore-dot-ghci MyFile.hs
GHCi, version 7.6.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[2 of 2] Compiling MyFile           ( MyFile.hs, interpreted )
Ok, modules loaded: MyFile, Util.Other.

忽略沒有為編譯提供的標志的違規.ghci ,未解釋未更改的Util.Other ,使用編譯的代碼。 (GHC <7.4時,忽略.ghci文件甚至是不必要的。)

如果你有一個.ghci文件,你在其中設置語言選項( NoMonomorphismRestrictionTypeFamilies ,...)和ghc> = 7.4,你需要在加載模塊時忽略.ghci文件。

如果不是這種情況,則重新編譯不是預期的行為。 然后需要更多信息來診斷問題並找到修復方法。

然后,半合作將是ghci的-fobject-code標志。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM