2012-11-28 2 views
3

GHCI에서 컴파일 된 객체 버전을 컴파일 할 때 컴파일 된 버전보다 훨씬 빠르도록로드하고 싶습니다. 이것은 모든 파일이 동일한 디렉토리 (모듈 계층이 없음)에있을 때 잘 작동했습니다. 그러나 파일이 모듈 계층에있을 때는 작동하지 않습니다.Haskell GHCI가 컴파일 된 객체 파일을로드하지 않음

근무 버전 MyFile.hs :

import Util.Basic 
import Util.Histogram 
: Basic.o 및 Histogram.o이 MyFile.hs

과 같은 디렉토리에 작동하지 버전 MyFile.hs 있습니다

import Basic 
import 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 파일이 컴파일 된 이후 소스 파일이 변경되지 않았 음을 유의해야합니다.

편집 :

import Util.Basic 
import Util.Histogram 

백분율/Basic.hs

module Util.Basic() where 

백분율/Histogram.hs

module Util.Histogram() where 

MyFile.hs : 여기 각 파일의 내용이다

파일/편집 : 다니엘에 의해 제안했다

$:~/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. 
+0

아, 좋습니다. 나는 당신이 서브 디렉토리에서 컴파일 된 것을 결코 상상하지 못했습니다. ghc로 가져와 가져온 파일을 찾아서 컴파일했다고 가정했습니다. –

답변

5

문제는 후술하는 바와 같이 동일, 플래그 변경 :

~/.../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) 

특히 어떤 플래그가 있는지, 또는 별도의 컴파일 중에 플래그가 전달 된 이유가 다른 플래그와 다른지를 확인하지 못했습니다. 가져 오기 모듈에서 쫓겨 모듈로 mpiling,하지만 그들은 변경하고, 따라서 재 컴파일이 필요합니다 (특히, .hi 파일의 플래그 해시 값이 변경).

따라서 수정 사항은 모듈을 개별적으로 컴파일하지 않고 최상위 가져 오기 프로그램의 종속 항목으로 컴파일해야합니다.


원래 거의 정확한 추측 :

난 단지 부분적으로 그것을 재현 할 수 있습니다.다음 컴파일 후 touch

$ 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. 

가 당신을 위해 같은 모양, MyFile.hs을 보내고 있지만, 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. 

플래그가 변경을 . 내 .ghci 파일에 :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. 

, 변경되지 않은 Util.Other 해석되지 않으며, 컴파일 된 코드가 사용됩니다. (GHC < 7.4으로, .ghci 파일을 무시하고 심지어 필요가 없습니다.)

, 당신이 필요로하는 당신은 언어 옵션 (NoMonomorphismRestriction, TypeFamilies, ...) 및 GHC> = 7.4을 설정하는 .ghci 파일이있는 경우 모듈을로드 할 때 .ghci 파일을 무시하십시오.

그렇지 않은 경우 재 컴파일이 예상 된 동작이 아닙니다. 그런 다음 문제를 진단하고 수정 사항을 찾는 데 더 많은 정보가 필요합니다.

반 가공은 ghci에 대한 -fobject-code 플래그가됩니다.

+0

이것은 그렇지 않습니다. '-ignore-dot-ghci' 플래그로 시작할 때조차도 계속 해석됩니다. 추가 출력을 사용하여 원래 게시물을 편집하고 있습니다. – Joe

+0

어떤 GHC 버전입니까? –

+0

7.4.1을 사용하고 있습니다. – Joe

관련 문제