[commit: ghc] ghc-7.10: Do not treat prim and javascript imports as C imports in TH and QQ (98587f0)
git at git.haskell.org
git at git.haskell.org
Wed Jul 15 09:32:11 UTC 2015
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-7.10
Link : http://ghc.haskell.org/trac/ghc/changeset/98587f0c34b15ed307a9a6f8ebc50fb5339b4042/ghc
>---------------------------------------------------------------
commit 98587f0c34b15ed307a9a6f8ebc50fb5339b4042
Author: Ben Gamari <ben at smart-cactus.org>
Date: Wed Jul 15 10:19:33 2015 +0200
Do not treat prim and javascript imports as C imports in TH and QQ
This fixes trac Trac #10638.
>---------------------------------------------------------------
98587f0c34b15ed307a9a6f8ebc50fb5339b4042
compiler/deSugar/DsMeta.hs | 8 +++++---
compiler/hsSyn/Convert.hs | 14 ++++++++++----
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/compiler/deSugar/DsMeta.hs b/compiler/deSugar/DsMeta.hs
index 63b6539..6eeba5e 100644
--- a/compiler/deSugar/DsMeta.hs
+++ b/compiler/deSugar/DsMeta.hs
@@ -491,12 +491,14 @@ repForD (L loc (ForeignImport name typ _ (CImport (L _ cc) (L _ s) mch cis _)))
conv_cimportspec (CFunction (StaticTarget fs _ True)) = return (unpackFS fs)
conv_cimportspec (CFunction (StaticTarget _ _ False)) = panic "conv_cimportspec: values not supported yet"
conv_cimportspec CWrapper = return "wrapper"
+ -- these calling conventions do not support headers and the static keyword
+ raw_cconv = cc == PrimCallConv || cc == JavaScriptCallConv
static = case cis of
- CFunction (StaticTarget _ _ _) -> "static "
+ CFunction (StaticTarget _ _ _) | not raw_cconv -> "static "
_ -> ""
chStr = case mch of
- Nothing -> ""
- Just (Header h) -> unpackFS h ++ " "
+ Just (Header h) | not raw_cconv -> unpackFS h ++ " "
+ _ -> ""
repForD decl = notHandled "Foreign declaration" (ppr decl)
repCCallConv :: CCallConv -> DsM (Core TH.Callconv)
diff --git a/compiler/hsSyn/Convert.hs b/compiler/hsSyn/Convert.hs
index 03c9bf5..8ffda3a 100644
--- a/compiler/hsSyn/Convert.hs
+++ b/compiler/hsSyn/Convert.hs
@@ -476,16 +476,22 @@ noExistentials = []
cvtForD :: Foreign -> CvtM (ForeignDecl RdrName)
cvtForD (ImportF callconv safety from nm ty)
+ | callconv == TH.Prim || callconv == TH.JavaScript
+ = mk_imp (CImport (noLoc (cvt_conv callconv)) (noLoc safety') Nothing
+ (CFunction (StaticTarget (mkFastString from) Nothing True))
+ (noLoc from))
| Just impspec <- parseCImport (noLoc (cvt_conv callconv)) (noLoc safety')
(mkFastString (TH.nameBase nm))
from (noLoc from)
- = do { nm' <- vNameL nm
- ; ty' <- cvtType ty
- ; return (ForeignImport nm' ty' noForeignImportCoercionYet impspec)
- }
+ = mk_imp impspec
| otherwise
= failWith $ text (show from) <+> ptext (sLit "is not a valid ccall impent")
where
+ mk_imp impspec
+ = do { nm' <- vNameL nm
+ ; ty' <- cvtType ty
+ ; return (ForeignImport nm' ty' noForeignImportCoercionYet impspec)
+ }
safety' = case safety of
Unsafe -> PlayRisky
Safe -> PlaySafe
More information about the ghc-commits
mailing list