X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Ftypecheck%2FTcForeign.lhs;h=f01f6a5788e9ebe3be138e1178d9206feaf0e5f9;hp=49ecffc357e74e17ed90d8397ff3015e61142710;hb=ad94d40948668032189ad22a0ad741ac1f645f50;hpb=474b582b68ea9289f3da4355da816164138604b0 diff --git a/compiler/typecheck/TcForeign.lhs b/compiler/typecheck/TcForeign.lhs index 49ecffc..f01f6a5 100644 --- a/compiler/typecheck/TcForeign.lhs +++ b/compiler/typecheck/TcForeign.lhs @@ -12,6 +12,13 @@ is restricted to what the outside world understands (read C), and this module checks to see if a foreign declaration has got a legal type. \begin{code} +{-# OPTIONS -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/CodingStyle#Warnings +-- for details + module TcForeign ( tcForeignImports @@ -35,11 +42,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 +223,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