我希望GHCI加载一个模块的编译对象代码,该模块在编译时明显快于无编译版本.当所有文件都在同一目录(没有模块层次结构)时,这很有效.但是,当文件位于模块层次结构中时,它们不起作用.
工作版MyFile.hs:
import Basic
import Histogram
Run Code Online (Sandbox Code Playgroud)
其中Basic.o和Histogram.o与MyFile.hs在同一目录中
不工作的版本MyFile.hs:
import Util.Basic
import Util.Histogram
Run Code Online (Sandbox Code Playgroud)
其中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.
Run Code Online (Sandbox Code Playgroud)
我希望能够在模块中组织我的代码,但仍然可以从使用编译的o文件中获益.
此外,应该注意的是,自编译o文件以来,源文件尚未更改.
编辑:以下是每个文件的内容:
MyFile.hs
import Util.Basic
import Util.Histogram
Run Code Online (Sandbox Code Playgroud)
UTIL/Basic.hs
module Util.Basic () where
Run Code Online (Sandbox Code Playgroud)
UTIL/Histogram.hs
module Util.Histogram () where
Run Code Online (Sandbox Code Playgroud)
文件/编译:
$:~/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>
Run Code Online (Sandbox Code Playgroud)
丹尼尔建议的解决方案:
The fix is to compile the importing file, and the files in the
subdirectory only as a consequence of that, not directly.
Run Code Online (Sandbox Code Playgroud)
问题与下面讨论的相同,标志发生了变化:
~/.../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 )
Run Code Online (Sandbox Code Playgroud)
我没有找到特别的标志,或者为什么在单独编译期间传递的标志与从编译作为从导入模块追逐的模块时传递的标志不同,但它们确实发生了变化,因此需要重新编译(具体来说,文件中的标志哈希值会.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.
Run Code Online (Sandbox Code Playgroud)
它看起来和你一样,但是对于7.6.1,我们得到一个提示(编译和touching):
$ 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.
Run Code Online (Sandbox Code Playgroud)
标志改变了.我:set -XNoMonomorphismRestriction在我的.ghci文件中,标志的更改导致重新编译.
$ 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.
Run Code Online (Sandbox Code Playgroud)
.ghci使用未为编译提供的标志忽略违规,Util.Other未解释未更改,使用编译的代码.(GHC <7.4时,.ghci甚至不需要忽略该文件.)
如果您有一个.ghci文件,其中您设置了语言选项(NoMonomorphismRestriction,, TypeFamilies...)和ghc> = 7.4,则.ghci在加载模块时需要忽略该文件.
如果不是这种情况,则重新编译不是预期的行为.然后需要更多信息来诊断问题并找到修复方法.
然后,半合作将成为-fobject-codeghci 的旗帜.