summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marlow <simonmar@microsoft.com>2007-08-28 09:15:50 +0000
committerSimon Marlow <simonmar@microsoft.com>2007-08-28 09:15:50 +0000
commitdf6d4b9ae4f9b5e167aec723b70aa20a448c01d6 (patch)
treec1e7ba4ee9f70c9a8d12a35c6f0d509808e57d1a
parentfa6c4bf01427a4191a595afecf90d96b27bad306 (diff)
downloadhaskell-df6d4b9ae4f9b5e167aec723b70aa20a448c01d6.tar.gz
FIX #1533: foreign exporing the same identifier multiple times gave a link error
We were generating a new top-level binding derived from the name of the existing top-level name, and making the name external. Multiple instances therefore clashed. The fix is to make each name unique, by appending an actual Unique to the derived name.
-rw-r--r--compiler/typecheck/TcForeign.lhs14
1 files changed, 13 insertions, 1 deletions
diff --git a/compiler/typecheck/TcForeign.lhs b/compiler/typecheck/TcForeign.lhs
index 49ecffc357..3b6ecd87e3 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