Opened 10 years ago

Closed 10 years ago

Last modified 8 years ago

#1027 closed bug (fixed)

GHC-as-a-library does too much recompilation when given recursive module imports

Reported by: igloo Owned by: simonmar
Priority: normal Milestone: 6.8.1
Component: Compiler Version: 6.6
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

In http://www.haskell.org/pipermail/glasgow-haskell-users/2006-October/011219.html (the archives seem to have lost the actual body text unfortunately) Brian Smith reports that the GHC API seems to do too much recompilation when used on the GHC sources. It looks like recursive module imports are the cause, as shown by the attached files. The session below shows 3 recompilations of A that should not be necessary; I'm not sure if we can also avoid the need to look at the hs-boot files again (perhaps by making a .hi-boot purely for timestamping purposes?).

$ rm *.o *.hi                         
$ ghc -package ghc foo.hs -o foo -Wall
$ ./foo 
[1 of 4] Compiling C[boot]          ( C.hs-boot, nothing )
[2 of 4] Compiling B                ( B.hs, B.o )

B.hs:6:0: Warning: Definition but no type signature for `b'
[3 of 4] Compiling A                ( A.hs, A.o )

A.hs:6:0: Warning: Definition but no type signature for `a'
[4 of 4] Compiling C                ( C.hs, C.o )

C.hs:6:0: Warning: Definition but no type signature for `c'

Succeeded!

[1 of 4] Compiling C[boot]          ( C.hs-boot, nothing )
[3 of 4] Compiling A                ( A.hs, A.o )

A.hs:6:0: Warning: Definition but no type signature for `a'

Succeeded!

[1 of 4] Compiling C[boot]          ( C.hs-boot, nothing )

Succeeded!

[1 of 4] Compiling C[boot]          ( C.hs-boot, nothing )

Succeeded!

$ ./foo
[1 of 4] Compiling C[boot]          ( C.hs-boot, nothing )
[3 of 4] Compiling A                ( A.hs, A.o )

A.hs:6:0: Warning: Definition but no type signature for `a'

Succeeded!

[1 of 4] Compiling C[boot]          ( C.hs-boot, nothing )
[3 of 4] Compiling A                ( A.hs, A.o )

A.hs:6:0: Warning: Definition but no type signature for `a'

Succeeded!

[1 of 4] Compiling C[boot]          ( C.hs-boot, nothing )

Succeeded!

[1 of 4] Compiling C[boot]          ( C.hs-boot, nothing )

Succeeded!
$ 

Attachments (5)

foo.hs (1.2 KB) - added by igloo 10 years ago.
A.hs (39 bytes) - added by igloo 10 years ago.
B.hs (54 bytes) - added by igloo 10 years ago.
C.hs (39 bytes) - added by igloo 10 years ago.
C.hs-boot (17 bytes) - added by igloo 10 years ago.

Download all attachments as: .zip

Change History (10)

Changed 10 years ago by igloo

Attachment: foo.hs added

Changed 10 years ago by igloo

Attachment: A.hs added

Changed 10 years ago by igloo

Attachment: B.hs added

Changed 10 years ago by igloo

Attachment: C.hs added

Changed 10 years ago by igloo

Attachment: C.hs-boot added

comment:1 Changed 10 years ago by simonmar

Owner: set to simonmar

See also #1322

I'll look at this

comment:2 Changed 10 years ago by simonmar

Resolution: fixed
Status: newclosed

Fixed. It looks like I fixed this as part of the changes to support compiling to object code in GHCi; the cause of the problem was that we weren't even attempting to avoid unnecessary recompilations to object code because --make doesn't recompile.

The trace is now:

~/scratch/ghcapi > ./foo
[1 of 4] Compiling C[boot]          ( C.hs-boot, nothing )
[2 of 4] Compiling B                ( B.hs, B.o )

B.hs:6:0:
    Warning: Definition but no type signature for `b'
             Inferred type: b :: Char
[3 of 4] Compiling A                ( A.hs, A.o )

A.hs:6:0:
    Warning: Definition but no type signature for `a'
             Inferred type: a :: Char
[4 of 4] Compiling C                ( C.hs, C.o )

C.hs:6:0:
    Warning: Definition but no type signature for `c'
             Inferred type: c :: Char

Succeeded!


Succeeded!


Succeeded!


Succeeded!

~/scratch/ghcapi > ./foo
[1 of 4] Compiling C[boot]          ( C.hs-boot, nothing )

Succeeded!


Succeeded!


Succeeded!


Succeeded!

The example code has to be tweaked slightly: the BatchCompile argument to newSession is no longer required.

comment:3 Changed 9 years ago by igloo

Milestone: 6.8 branch6.8.1

comment:4 Changed 8 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:5 Changed 8 years ago by simonmar

Operating System: UnknownUnknown/Multiple
Note: See TracTickets for help on using tickets.