Odd c2hs error
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
I've put together a repo that reproduces what I thought was a `language-c` bug, but cabal is behaving oddly as well.
The repo:
https://github.com/mitchellwrosen/language-c-issue-54
To reproduce:
- Run `./build` once:
```
Resolving dependencies...
Build profile: -w ghc-8.4.3 -O1
In order, the following will be built (use -v for more details):
- foo-0 (lib:foo) (first run)
Configuring foo-0...
Preprocessing library for foo-0..
c2hs: Errors during generation of C wrappers:
./Foo.chs:9: (column 4) [ERROR] >>> Internal wrapper error!
Something went wrong generating a bare structure wrapper.
makeArg:arg=False
cdecl=CDecl [CTypeSpec (CTypeDef (Ident "WINDOW" 143904934 (NodeInfo ("./foo.h": line 1635) (("./foo.h": line 1635),6) (Name {nameId = 4053}))) (NodeInfo ("./foo.h": line 1635) (("./foo.h": line 1635),6) (Name {nameId = 4054})))] [(Just (CDeclr Nothing [CPtrDeclr [] (NodeInfo ("./foo.h": line 1635) (("./foo.h": line 1635),1) (Name {nameId = 4055}))] Nothing [] (OnlyPos (,-1))),Nothing,Nothing)] (NodeInfo ("./foo.h": line 1635) (("./foo.h": line 1635),1) (Name {nameId = 4056}))
idx=1
```
- Run `./build` again:
```
Build profile: -w ghc-8.4.3 -O1
In order, the following will be built (use -v for more details):
- foo-0 (lib:foo) (first run)
Preprocessing library for foo-0..
Building library for foo-0..
[1 of 1] Compiling Foo ( /home/mitchell/junk/dist-newstyle/build/x86_64-linux/ghc-8.4.3/foo-0/build/Foo.hs, /home/mitchell/junk/dist-newstyle/build/x86_64-linux/ghc-8.4.3/foo-0/build/Foo.o )
ignoring (possibly broken) abi-depends field for packages
```
For some reason, `c2hs` barfs the first time, then stops complaining. The generated file looks fine to me, even after only one invocation of `./build`:
```
$ cat $(find dist-newstyle -name Foo.hs)
-- GENERATED by C->Haskell Compiler, version 0.28.3 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!
{-# LINE 1 "./Foo.chs" #-}
{-# language ForeignFunctionInterface #-}
module Foo where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
type Window = C2HSImp.Ptr (())
{-# LINE 7 "./Foo.chs" #-}
keypad :: (Window) -> (Bool) -> IO ((Int))
keypad a1 a2 =
let {a1' = id a1} in
let {a2' = C2HSImp.fromBool a2} in
keypad'_ a1' a2' >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 9 "./Foo.chs" #-}
foreign import ccall safe "Foo.chs.h __c2hs_wrapped__keypad"
keypad'_ :: ((Window) -> (C2HSImp.CInt{-bool-} -> (IO C2HSImp.CInt)))
```
Sorry for the mess of info, I'm not too sure what's going on here :) Thanks.
Contributor guide
Research direction
Start by running the linked reproduction with ./build twice and compare the first c2hs failure with the second successful build. Inspect Foo.chs, the generated Foo.hs, and the Cabal preprocessing output to locate why the first invocation reports an internal wrapper error. Done means identifying and fixing the inconsistent first-run behavior, with the two-run reproduction no longer showing different results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100