[GHC] #13269: Changes in includes of addCStub do not cause recompilation of downstream modules.

GHC ghc-devs at haskell.org
Sat Feb 11 18:08:38 UTC 2017


#13269: Changes in includes of addCStub do not cause recompilation of downstream
modules.
-------------------------------------+-------------------------------------
        Reporter:                    |                Owner:
  facundo.dominguez                  |
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Template Haskell  |              Version:  8.0.1
      Resolution:                    |             Keywords:  inline-c
                                     |  addCStub addDependentFile
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #13237            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by facundo.dominguez):

 * keywords:  inline-c addCStub => inline-c addCStub addDependentFile


@@ -3,1 +3,1 @@
- // header.h
+ // f.c
@@ -23,2 +23,2 @@
- do addCStub "#include \"header.h\""
-    addDependentFile "header.h"
+ do addCStub "#include \"f.c\""
+    addDependentFile "f.c"
@@ -52,1 +52,1 @@
- Edit `header.h`:
+ Edit `f.c`:
@@ -54,1 +54,1 @@
-  // header.h
+  // f.c
@@ -67,1 +67,1 @@
- [1 of 2] Compiling A                ( A.hs, A.o ) [header.h changed]
+ [1 of 2] Compiling A                ( A.hs, A.o ) [f.c changed]

New description:

 Failing example:
 {{{
 // f.c
 #include <stdio.h>

 int f(int  x) {
     printf("calling f(%d)\n",x);
     return x + 1;
 }
 }}}

 {{{
 -- A.hs
 {-# LANGUAGE ForeignFunctionInterface #-}
 {-# LANGUAGE TemplateHaskell #-}

 module A where

 import Language.Haskell.TH.Syntax

 foreign import ccall f :: Int -> IO Int

 do addCStub "#include \"f.c\""
    addDependentFile "f.c"
    return []
 }}}
 {{{
 -- B.hs
 {-# LANGUAGE ForeignFunctionInterface #-}
 {-# LANGUAGE TemplateHaskell #-}

 module Main where

 import Language.Haskell.TH.Syntax
 import A

 do i <- runIO $ f 0
    [d| fh = i |]

 main :: IO ()
 main = print fh
 }}}
 {{{
 $ ghc --make B.hs
 [1 of 2] Compiling A                ( A.hs, A.o )
 [2 of 2] Compiling Main             ( B.hs, B.o )
 calling f(0)
 Linking B ...
 $ ./B
 1
 }}}
 Edit `f.c`:
 {{{
  // f.c
  #include <stdio.h>

  int f(int  x) {
      printf("calling f(%d)\n",x);
 -    return x + 1;
 +    return x + 2;
  }
 }}}
 Recompiling we can see that `B.hs` is not rebuilt and executing the
 program still shows the old result.
 {{{
 $ ghc --make B.hs
 [1 of 2] Compiling A                ( A.hs, A.o ) [f.c changed]
 Linking B ...
 $ ./B
 1
 }}}

--

Comment:

 Perhaps it could be fixed by adding a hash of the files pointed with
 `addDependendFile` to the module interface file.

 nh2 proposed in #13237 adding a hash of the cpp output over the string
 given to `addCStub`.

 Note though, that this behavior can be experienced without `addCStub` if
 one replaces `A.hs` with
 {{{
 -- A.hs
 {-# LANGUAGE ForeignFunctionInterface #-}
 module A where
 import Language.Haskell.TH.Syntax
 foreign import ccall f :: Int -> IO Int
 }}}
 and builds with:
 {{{
 $ ghc --make B.hs f.c -fPIC
 }}}
 I don't have ideas to fix this case.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13269#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list