module checks to see if a foreign declaration has got a legal type.
\begin{code}
+{-# OPTIONS_GHC -w #-}
+-- The above warning supression flag is a temporary kludge.
+-- While working on this module you are encouraged to remove it and fix
+-- any warnings in the module. See
+-- http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
+-- for details
+
module TcForeign
(
tcForeignImports
import MachOp
#endif
import Name
+import OccName
import TcType
import DynFlags
import Outputable
import SrcLoc
import Bag
+import Unique
\end{code}
\begin{code}
newUnique `thenM` \ uniq ->
getModule `thenM` \ mod ->
let
- gnm = mkExternalName uniq mod (mkForeignExportOcc (getOccName nm)) loc
+ -- We need to give a name to the new top-level binding that
+ -- is *stable* (i.e. the compiler won't change it later),
+ -- because this name will be referred to by the C code stub.
+ -- Furthermore, the name must be unique (see #1533). If the
+ -- same function is foreign-exported multiple times, the
+ -- top-level bindings generated must not have the same name.
+ -- Hence we create an External name (doesn't change), and we
+ -- append a Unique to the string right here.
+ uniq_str = showSDoc (pprUnique uniq)
+ occ = mkVarOcc (occNameString (getOccName nm) ++ '_' : uniq_str)
+ gnm = mkExternalName uniq mod (mkForeignExportOcc occ) loc
id = mkExportedLocalId gnm sig_ty
bind = L loc (VarBind id rhs)
in
checkForeignRes non_io_result_ok pred_res_ty ty
-- (IO t) is ok, and so is any newtype wrapping thereof
- | Just (io, res_ty) <- tcSplitIOType_maybe ty,
+ | Just (io, res_ty, _) <- tcSplitIOType_maybe ty,
pred_res_ty res_ty
= returnM ()