haskell / c2hs

c2hs is a pre-processor for Haskell FFI bindings to C libraries
http://hackage.haskell.org/package/c2hs
Other
198 stars 50 forks source link

Redundant import when creating foreign #pointer #173

Open dbeacham opened 8 years ago

dbeacham commented 8 years ago

e.g.

module Test where

data Test
{#pointer *test as TestPtr foreign -> Test}

generates

module Test where

import qualified Foreign.ForeignPtr as C2HSImp
import qualified Foreign.Ptr as C2HSImp

data Test
type TestPtr = C2HSImp.ForeignPtr (Test)

The extra (unused) Foreign.Ptr import blows up on -Werror.

ag-eitilt commented 5 years ago

I've run into something very similar to fix alongside the above, when the (admittedly low priority) bug does get addressed: those same two imports are added even if the macro includes nocode. The type safety (-> Test) doesn't affect things.

Basically, it seems like every #pointer macro imports Foreign.Ptr and every #pointer ... foreign also imports Foreign.ForeignPtr. In certain cases, those are not necessary:

I suppose it's possible that the registration requires those types to be present, but not knowing the backend code, I'd guess it's probably fine leaving (or moving) the importing of those modules to #fun or other macros, which would probably be needing them for other reasons anyway.