X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Ftypecheck%2FTcForeign.lhs;h=3b6ecd87e3abb7666ee948880632d1fb57918b94;hb=a27d12f02b8ab3a3222c351dcf7e9168dfe05fb0;hp=a7101118b04567be8f7c7c4ee9fe0c99202eb3ca;hpb=940524aec90652b5ef81789c9a453c57c0e42cc9;p=ghc-hetmet.git diff --git a/compiler/typecheck/TcForeign.lhs b/compiler/typecheck/TcForeign.lhs index a710111..3b6ecd8 100644 --- a/compiler/typecheck/TcForeign.lhs +++ b/compiler/typecheck/TcForeign.lhs @@ -35,11 +35,13 @@ import SMRep import MachOp #endif import Name +import OccName import TcType import DynFlags import Outputable import SrcLoc import Bag +import Unique \end{code} \begin{code} @@ -214,7 +216,17 @@ tcFExport fo@(ForeignExport (L loc nm) hs_ty spec) = 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 @@ -263,7 +275,7 @@ mustBeIO = False 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 ()