TcForeign.lhs 19.5 KB
Newer Older
sof's avatar
sof committed
1
%
2
% (c) The University of Glasgow 2006
sof's avatar
sof committed
3
4
5
6
7
8
9
10
11
12
13
14
% (c) The AQUA Project, Glasgow University, 1998
%
\section[TcForeign]{Typechecking \tr{foreign} declarations}

A foreign declaration is used to either give an externally
implemented function a Haskell type (and calling interface) or
give a Haskell function an external calling interface. Either way,
the range of argument and result types these functions can accommodate
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}
dterei's avatar
dterei committed
15
16
17
module TcForeign
        (
          tcForeignImports
sof's avatar
sof committed
18
        , tcForeignExports
dterei's avatar
dterei committed
19
        ) where
sof's avatar
sof committed
20

21
22
#include "HsVersions.h"

23
import HsSyn
sof's avatar
sof committed
24

25
import TcRnMonad
26
27
import TcHsType
import TcExpr
28
import TcEnv
29
import RnEnv
sof's avatar
sof committed
30

31
32
import FamInst
import FamInstEnv
33
import Coercion      
34
35
import Type
import TypeRep
36
37
38
39
import ForeignCall
import ErrUtils
import Id
import Name
40
41
42
import RdrName
import DataCon
import TyCon
43
import TcType
44
import PrelNames
45
import DynFlags
sof's avatar
sof committed
46
import Outputable
Ian Lynagh's avatar
Ian Lynagh committed
47
import Platform
48
49
import SrcLoc
import Bag
50
import FastString
Ian Lynagh's avatar
Ian Lynagh committed
51
52

import Control.Monad
sof's avatar
sof committed
53
54
\end{code}

55
56
\begin{code}
-- Defines a binding
57
isForeignImport :: LForeignDecl name -> Bool
58
59
isForeignImport (L _ (ForeignImport _ _ _ _)) = True
isForeignImport _                             = False
60
61

-- Exports a binding
62
isForeignExport :: LForeignDecl name -> Bool
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
isForeignExport (L _ (ForeignExport _ _ _ _)) = True
isForeignExport _                             = False
\end{code}

\begin{code}
-- normaliseFfiType takes the type from an FFI declaration, and
-- evaluates any type synonyms, type functions, and newtypes. However,
-- we are only allowed to look through newtypes if the constructor is
-- in scope.
normaliseFfiType :: Type -> TcM (Coercion, Type)
normaliseFfiType ty
    = do fam_envs <- tcGetFamInstEnvs
         normaliseFfiType' fam_envs ty

normaliseFfiType' :: FamInstEnvs -> Type -> TcM (Coercion, Type)
normaliseFfiType' env ty0 = go [] ty0
  where
    go :: [TyCon] -> Type -> TcM (Coercion, Type)
    go rec_nts ty | Just ty' <- coreView ty     -- Expand synonyms
        = go rec_nts ty'

    go rec_nts ty@(TyConApp tc tys)
        -- We don't want to look through the IO newtype, even if it is
        -- in scope, so we have a special case for it:
Simon Peyton Jones's avatar
Simon Peyton Jones committed
87
        | tc_key `elem` [ioTyConKey, funPtrTyConKey]
88
        = children_only
Simon Peyton Jones's avatar
Simon Peyton Jones committed
89

90
91
92
93
94
95
96
97
98
99
100
101
102
        | isNewTyCon tc         -- Expand newtypes
        -- We can't just use isRecursiveTyCon here, as we need to allow
        -- some recursive types as described below
        = if tc `elem` rec_nts  -- See Note [Expanding newtypes] in Type.lhs
          then -- If this is a recursive newtype then it will normally
               -- be rejected later as not being a valid FFI type.
               -- Sometimes recursion is OK though, e.g. with
               --     newtype T = T (Ptr T)
               -- we don't reject the type for being recursive.
               return (Refl ty, ty)
          else do newtypeOK <- do env <- getGblEnv
                                  case tyConSingleDataCon_maybe tc of
                                      Just dataCon ->
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
                                          case lookupGRE_Name (tcg_rdr_env env) $ dataConName dataCon of
                                              [gre] ->
                                                  do -- If we look through a newtype constructor, then we need it to be in scope.
                                                     -- But if this is the only use if that import then we'll get an unused import
                                                     -- warning, so we need to mark a valid RdrName for it as used.
                                                     case gre_prov gre of
                                                         Imported (is : _) ->
                                                             do let modName = is_as (is_decl is)
                                                                    occName = nameOccName (dataConName dataCon)
                                                                    rdrName = mkRdrQual modName occName
                                                                addUsedRdrNames [rdrName]
                                                         Imported [] ->
                                                             panic "normaliseFfiType': Imported []"
                                                         LocalDef ->
                                                             return ()
                                                     return True
                                              [] ->
                                                  return False
                                              _ ->
                                                  panic "normaliseFfiType': Got more GREs than expected"
123
124
                                      _ ->
                                          return False
125
126
127
128
129
130
131
132
133
134
                  when (not newtypeOK) $
                     -- later: stop_here
                    addWarnTc (ptext (sLit "newtype") <+> quotes (ppr tc) <+>
                               ptext (sLit "is used in an FFI declaration,") $$
                               ptext (sLit "but its constructor is not in scope.") $$
                               ptext (sLit "This will become an error in GHC 7.6.1."))

                  let nt_co = mkAxInstCo (newTyConCo tc) tys
                  add_co nt_co rec_nts' nt_rhs

135
136
137
138
        | isFamilyTyCon tc              -- Expand open tycons
        , (co, ty) <- normaliseTcApp env tc tys
        , not (isReflCo co)
        = add_co co rec_nts ty
139

140
        | otherwise
141
142
143
144
145
        = return (mkReflCo ty, ty)
            -- If we have reached an ordinary (non-newtype) type constructor,
            -- we are done.  Note that we don't need to normalise the arguments,
            -- because whether an FFI type is legal or not depends only on
            -- the top-level type constructor (e.g. "Ptr a" is valid for all a).
146
        where
Simon Peyton Jones's avatar
Simon Peyton Jones committed
147
          tc_key = getUnique tc
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
          children_only = do xs <- mapM (go rec_nts) tys
                             let (cos, tys') = unzip xs
                             return (mkTyConAppCo tc cos, mkTyConApp tc tys')
          nt_rhs = newTyConInstRhs tc tys
          rec_nts' | isRecursiveTyCon tc = tc:rec_nts
                   | otherwise           = rec_nts

    go rec_nts (AppTy ty1 ty2)
      = do (coi1, nty1) <- go rec_nts ty1
           (coi2, nty2) <- go rec_nts ty2
           return (mkAppCo coi1 coi2, mkAppTy nty1 nty2)

    go rec_nts (FunTy ty1 ty2)
      = do (coi1,nty1) <- go rec_nts ty1
           (coi2,nty2) <- go rec_nts ty2
           return (mkFunCo coi1 coi2, mkFunTy nty1 nty2)

    go rec_nts (ForAllTy tyvar ty1)
      = do (coi,nty1) <- go rec_nts ty1
           return (mkForAllCo tyvar coi, ForAllTy tyvar nty1)

    go _ ty@(TyVarTy _)
      = return (Refl ty, ty)

    add_co co rec_nts ty
        = do (co', ty') <- go rec_nts ty
             return (mkTransCo co co', ty')
175
176
177
\end{code}

%************************************************************************
dterei's avatar
dterei committed
178
%*                                                                      *
179
\subsection{Imports}
dterei's avatar
dterei committed
180
%*                                                                      *
181
182
%************************************************************************

sof's avatar
sof committed
183
\begin{code}
184
tcForeignImports :: [LForeignDecl Name] -> TcM ([Id], [LForeignDecl Id])
185
tcForeignImports decls
186
  = mapAndUnzipM (wrapLocSndM tcFImport) (filter isForeignImport decls)
sof's avatar
sof committed
187

188
tcFImport :: ForeignDecl Name -> TcM (Id, ForeignDecl Id)
189
tcFImport fo@(ForeignImport (L loc nm) hs_ty _ imp_decl)
dterei's avatar
dterei committed
190
191
  = addErrCtxt (foreignDeclCtxt fo)  $
    do { sig_ty <- tcHsSigType (ForSigCtxt nm) hs_ty
192
       ; (norm_co, norm_sig_ty) <- normaliseFfiType sig_ty
dterei's avatar
dterei committed
193
194
195
       ; let
           -- Drop the foralls before inspecting the
           -- structure of the foreign type.
196
             (_, t_ty)         = tcSplitForAllTys norm_sig_ty
dterei's avatar
dterei committed
197
198
199
200
201
202
203
204
205
             (arg_tys, res_ty) = tcSplitFunTys t_ty
             id                = mkLocalId nm sig_ty
                 -- Use a LocalId to obey the invariant that locally-defined
                 -- things are LocalIds.  However, it does not need zonking,
                 -- (so TcHsSyn.zonkForeignExports ignores it).

       ; imp_decl' <- tcCheckFIType sig_ty arg_tys res_ty imp_decl
          -- Can't use sig_ty here because sig_ty :: Type and
          -- we need HsType Id hence the undefined
206
       ; return (id, ForeignImport (L loc id) undefined (mkSymCo norm_co) imp_decl') }
Ian Lynagh's avatar
Ian Lynagh committed
207
tcFImport d = pprPanic "tcFImport" (ppr d)
208
209
210
211
212
\end{code}


------------ Checking types for foreign import ----------------------
\begin{code}
Ian Lynagh's avatar
Ian Lynagh committed
213
tcCheckFIType :: Type -> [Type] -> Type -> ForeignImport -> TcM ForeignImport
sof's avatar
sof committed
214

Ian Lynagh's avatar
Ian Lynagh committed
215
tcCheckFIType sig_ty arg_tys res_ty idecl@(CImport _ _ _ (CLabel _))
216
  = ASSERT( null arg_tys )
217
    do { checkCg checkCOrAsmOrLlvmOrInterp
218
       ; check (isFFILabelTy res_ty) (illegalForeignTyErr empty sig_ty)
dterei's avatar
dterei committed
219
220
       ; return idecl }      -- NB check res_ty not sig_ty!
                             --    In case sig_ty is (forall a. ForeignPtr a)
221

Ian Lynagh's avatar
Ian Lynagh committed
222
tcCheckFIType sig_ty arg_tys res_ty idecl@(CImport cconv _ _ CWrapper) = do
dterei's avatar
dterei committed
223
224
225
226
227
        -- Foreign wrapper (former f.e.d.)
        -- The type must be of the form ft -> IO (FunPtr ft), where ft is a
        -- valid foreign type.  For legacy reasons ft -> IO (Ptr ft) as well
        -- as ft -> IO Addr is accepted, too.  The use of the latter two forms
        -- is DEPRECATED, though.
228
    checkCg checkCOrAsmOrLlvmOrInterp
229
230
231
    checkCConv cconv
    case arg_tys of
        [arg1_ty] -> do checkForeignArgs isFFIExternalTy arg1_tys
232
233
                        checkForeignRes nonIOok  checkSafe isFFIExportResultTy res1_ty
                        checkForeignRes mustBeIO checkSafe isFFIDynResultTy    res_ty
Simon Peyton Jones's avatar
Simon Peyton Jones committed
234
                                 -- ToDo: Why are res1_ty and res_ty not equal?
235
236
                  where
                     (arg1_tys, res1_ty) = tcSplitFunTys arg1_ty
Ian Lynagh's avatar
Ian Lynagh committed
237
        _ -> addErrTc (illegalForeignTyErr empty sig_ty)
sof's avatar
sof committed
238
    return idecl
239

240
tcCheckFIType sig_ty arg_tys res_ty idecl@(CImport cconv safety _ (CFunction target))
241
  | isDynamicTarget target = do -- Foreign import dynamic
242
      checkCg checkCOrAsmOrLlvmOrInterp
243
244
245
246
247
248
249
250
251
252
      checkCConv cconv
      case arg_tys of           -- The first arg must be Ptr, FunPtr, or Addr
        []                -> do
          check False (illegalForeignTyErr empty sig_ty)
          return idecl
        (arg1_ty:arg_tys) -> do
          dflags <- getDOpts
          check (isFFIDynArgumentTy arg1_ty)
                (illegalForeignTyErr argument arg1_ty)
          checkForeignArgs (isFFIArgumentTy dflags safety) arg_tys
253
          checkForeignRes nonIOok checkSafe (isFFIImportResultTy dflags) res_ty
254
          return idecl
255
  | cconv == PrimCallConv = do
256
      dflags <- getDOpts
257
      check (xopt Opt_GHCForeignImportPrim dflags)
258
            (text "Use -XGHCForeignImportPrim to allow `foreign import prim'.")
259
      checkCg (checkCOrAsmOrLlvmOrDotNetOrInterp)
260
      checkCTarget target
261
262
      check (playSafe safety)
            (text "The safe/unsafe annotation should not be used with `foreign import prim'.")
263
264
      checkForeignArgs (isFFIPrimArgumentTy dflags) arg_tys
      -- prim import result is more liberal, allows (#,,#)
265
      checkForeignRes nonIOok checkSafe (isFFIPrimResultTy dflags) res_ty
266
      return idecl
267
  | otherwise = do              -- Normal foreign import
268
      checkCg checkCOrAsmOrLlvmOrDotNetOrInterp
269
270
271
272
      checkCConv cconv
      checkCTarget target
      dflags <- getDOpts
      checkForeignArgs (isFFIArgumentTy dflags safety) arg_tys
273
      checkForeignRes nonIOok checkSafe (isFFIImportResultTy dflags) res_ty
274
      checkMissingAmpersand dflags arg_tys res_ty
275
      return idecl
276

277

278
279
-- This makes a convenient place to check
-- that the C identifier is valid for C
Ian Lynagh's avatar
Ian Lynagh committed
280
checkCTarget :: CCallTarget -> TcM ()
281
checkCTarget (StaticTarget str _) = do
282
    checkCg checkCOrAsmOrLlvmOrDotNetOrInterp
283
284
    check (isCLabelString str) (badCName str)

Ian Lynagh's avatar
Ian Lynagh committed
285
checkCTarget DynamicTarget = panic "checkCTarget DynamicTarget"
286

287

288
289
290
checkMissingAmpersand :: DynFlags -> [Type] -> Type -> TcM ()
checkMissingAmpersand dflags arg_tys res_ty
  | null arg_tys && isFunPtrTy res_ty &&
291
    wopt Opt_WarnDodgyForeignImports dflags
292
293
294
  = addWarn (ptext (sLit "possible missing & in foreign import of FunPtr"))
  | otherwise
  = return ()
295
\end{code}
296

297
%************************************************************************
dterei's avatar
dterei committed
298
%*                                                                      *
299
\subsection{Exports}
dterei's avatar
dterei committed
300
%*                                                                      *
301
302
303
%************************************************************************

\begin{code}
dterei's avatar
dterei committed
304
305
tcForeignExports :: [LForeignDecl Name]
                 -> TcM (LHsBinds TcId, [LForeignDecl TcId])
306
tcForeignExports decls
307
  = foldlM combine (emptyLHsBinds, []) (filter isForeignExport decls)
sof's avatar
sof committed
308
  where
309
310
311
   combine (binds, fs) fe = do
       (b, f) <- wrapLocSndM tcFExport fe
       return (b `consBag` binds, f:fs)
sof's avatar
sof committed
312

313
tcFExport :: ForeignDecl Name -> TcM (LHsBind Id, ForeignDecl Id)
314
tcFExport fo@(ForeignExport (L loc nm) hs_ty _ spec)
dterei's avatar
dterei committed
315
  = addErrCtxt (foreignDeclCtxt fo) $ do
sof's avatar
sof committed
316

dterei's avatar
dterei committed
317
318
    sig_ty <- tcHsSigType (ForSigCtxt nm) hs_ty
    rhs <- tcPolyExpr (nlHsVar nm) sig_ty
319

320
321
322
    (norm_co, norm_sig_ty) <- normaliseFfiType sig_ty

    tcCheckFEType norm_sig_ty spec
sof's avatar
sof committed
323

dterei's avatar
dterei committed
324
325
326
327
           -- we're exporting a function, but at a type possibly more
           -- constrained than its declared/inferred type. Hence the need
           -- to create a local binding which will call the exported function
           -- at a particular type (and, maybe, overloading).
328

329

dterei's avatar
dterei committed
330
331
332
333
    -- 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.
    id  <- mkStableIdFromName nm sig_ty loc mkForeignExportOcc
334
    return (mkVarBind id rhs, ForeignExport (L loc id) undefined norm_co spec)
Ian Lynagh's avatar
Ian Lynagh committed
335
tcFExport d = pprPanic "tcFExport" (ppr d)
336
337
338
\end{code}

------------ Checking argument types for foreign export ----------------------
sof's avatar
sof committed
339

340
\begin{code}
Ian Lynagh's avatar
Ian Lynagh committed
341
tcCheckFEType :: Type -> ForeignExport -> TcM ()
342
tcCheckFEType sig_ty (CExport (CExportStatic str cconv)) = do
343
    checkCg checkCOrAsmOrLlvm
344
    check (isCLabelString str) (badCName str)
345
    checkCConv cconv
346
    checkForeignArgs isFFIExternalTy arg_tys
347
    checkForeignRes nonIOok noCheckSafe isFFIExportResultTy res_ty
348
349
350
  where
      -- Drop the foralls before inspecting n
      -- the structure of the foreign type.
351
352
    (_, t_ty) = tcSplitForAllTys sig_ty
    (arg_tys, res_ty) = tcSplitFunTys t_ty
sof's avatar
sof committed
353
354
355
\end{code}


356
357

%************************************************************************
dterei's avatar
dterei committed
358
%*                                                                      *
359
\subsection{Miscellaneous}
dterei's avatar
dterei committed
360
%*                                                                      *
361
362
%************************************************************************

sof's avatar
sof committed
363
\begin{code}
364
------------ Checking argument types for foreign import ----------------------
365
checkForeignArgs :: (Type -> Bool) -> [Type] -> TcM ()
366
367
checkForeignArgs pred tys = mapM_ go tys
  where go ty = check (pred ty) (illegalForeignTyErr argument ty)
368
369

------------ Checking result types for foreign calls ----------------------
370
-- | Check that the type has the form
371
--    (IO t) or (t) , and that t satisfies the given predicate.
372
373
374
375
376
-- When calling this function, any newtype wrappers (should) have been
-- already dealt with by normaliseFfiType.
-- 
-- We also check that the Safe Haskell condition of FFI imports having
-- results in the IO monad holds.
sof's avatar
sof committed
377
--
378
checkForeignRes :: Bool -> Bool -> (Type -> Bool) -> Type -> TcM ()
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
checkForeignRes non_io_result_ok check_safe pred_res_ty ty
  = case tcSplitIOType_maybe ty of
        -- Got an IO result type, that's always fine!
        Just (_, res_ty) | pred_res_ty res_ty -> return ()

        -- Case for non-IO result type with FFI Import
        _ -> do
            dflags <- getDOpts
            case (pred_res_ty ty && non_io_result_ok) of
                -- handle normal typecheck fail, we want to handle this first and
                -- only report safe haskell errors if the normal type check is OK.
                False -> addErrTc $ illegalForeignTyErr result ty

                -- handle safe infer fail
                _ | check_safe && safeInferOn dflags
                    -> recordUnsafeInfer

                -- handle safe language typecheck fail
                _ | check_safe && safeLanguageOn dflags
                    -> addErrTc $ illegalForeignTyErr result ty $+$ safeHsErr

                -- sucess! non-IO return is fine
                _ -> return ()

  where 
    safeHsErr = ptext $ sLit "Safe Haskell is on, all FFI imports must be in the IO monad"
405

Ian Lynagh's avatar
Ian Lynagh committed
406
nonIOok, mustBeIO :: Bool
407
408
409
nonIOok  = True
mustBeIO = False

410
411
412
checkSafe, noCheckSafe :: Bool
checkSafe   = True
noCheckSafe = False
sof's avatar
sof committed
413
414
\end{code}

415
416
Checking a supported backend is in use

417
\begin{code}
418
419
420
421
422
checkCOrAsmOrLlvm :: HscTarget -> Maybe SDoc
checkCOrAsmOrLlvm HscC    = Nothing
checkCOrAsmOrLlvm HscAsm  = Nothing
checkCOrAsmOrLlvm HscLlvm = Nothing
checkCOrAsmOrLlvm _
dterei's avatar
dterei committed
423
  = Just (text "requires via-C, llvm (-fllvm) or native code generation (-fvia-C)")
424
425
426
427
428
429
430

checkCOrAsmOrLlvmOrInterp :: HscTarget -> Maybe SDoc
checkCOrAsmOrLlvmOrInterp HscC           = Nothing
checkCOrAsmOrLlvmOrInterp HscAsm         = Nothing
checkCOrAsmOrLlvmOrInterp HscLlvm        = Nothing
checkCOrAsmOrLlvmOrInterp HscInterpreted = Nothing
checkCOrAsmOrLlvmOrInterp _
dterei's avatar
dterei committed
431
  = Just (text "requires interpreted, C, Llvm or native code generation")
432
433
434
435
436
437
438

checkCOrAsmOrLlvmOrDotNetOrInterp :: HscTarget -> Maybe SDoc
checkCOrAsmOrLlvmOrDotNetOrInterp HscC           = Nothing
checkCOrAsmOrLlvmOrDotNetOrInterp HscAsm         = Nothing
checkCOrAsmOrLlvmOrDotNetOrInterp HscLlvm        = Nothing
checkCOrAsmOrLlvmOrDotNetOrInterp HscInterpreted = Nothing
checkCOrAsmOrLlvmOrDotNetOrInterp _
dterei's avatar
dterei committed
439
  = Just (text "requires interpreted, C, Llvm or native code generation")
440

Ian Lynagh's avatar
Ian Lynagh committed
441
checkCg :: (HscTarget -> Maybe SDoc) -> TcM ()
442
checkCg check = do
dterei's avatar
dterei committed
443
444
445
446
447
448
449
450
    dflags <- getDOpts
    let target = hscTarget dflags
    case target of
      HscNothing -> return ()
      _ ->
        case check target of
          Nothing  -> return ()
          Just err -> addErrTc (text "Illegal foreign declaration:" <+> err)
SamB's avatar
SamB committed
451
\end{code}
dterei's avatar
dterei committed
452

453
454
455
456
Calling conventions

\begin{code}
checkCConv :: CCallConv -> TcM ()
dterei's avatar
dterei committed
457
checkCConv CCallConv    = return ()
458
checkCConv CApiConv     = return ()
Ian Lynagh's avatar
Ian Lynagh committed
459
460
461
462
463
checkCConv StdCallConv  = do dflags <- getDOpts
                             let platform = targetPlatform dflags
                             unless (platformArch platform == ArchX86) $
                                 -- This is a warning, not an error. see #3336
                                 addWarnTc (text "the 'stdcall' calling convention is unsupported on this platform," $$ text "treating as ccall")
464
checkCConv PrimCallConv = addErrTc (text "The `prim' calling convention can only be used with `foreign import'")
dterei's avatar
dterei committed
465
checkCConv CmmCallConv  = panic "checkCConv CmmCallConv"
466
467
\end{code}

sof's avatar
sof committed
468
469
470
Warnings

\begin{code}
471
check :: Bool -> Message -> TcM ()
dterei's avatar
dterei committed
472
check True _       = return ()
473
check _    the_err = addErrTc the_err
474

Ian Lynagh's avatar
Ian Lynagh committed
475
illegalForeignTyErr :: SDoc -> Type -> SDoc
476
illegalForeignTyErr arg_or_res ty
dterei's avatar
dterei committed
477
  = hang (hsep [ptext (sLit "Unacceptable"), arg_or_res,
Ian Lynagh's avatar
Ian Lynagh committed
478
                ptext (sLit "type in foreign declaration:")])
479
       2 (hsep [ppr ty])
sof's avatar
sof committed
480

481
-- Used for 'arg_or_res' argument to illegalForeignTyErr
Ian Lynagh's avatar
Ian Lynagh committed
482
argument, result :: SDoc
483
484
485
486
argument = text "argument"
result   = text "result"

badCName :: CLabelString -> Message
dterei's avatar
dterei committed
487
488
badCName target
  = sep [quotes (ppr target) <+> ptext (sLit "is not a valid C identifier")]
489

Ian Lynagh's avatar
Ian Lynagh committed
490
foreignDeclCtxt :: ForeignDecl Name -> SDoc
491
foreignDeclCtxt fo
Ian Lynagh's avatar
Ian Lynagh committed
492
  = hang (ptext (sLit "When checking declaration:"))
493
       2 (ppr fo)
sof's avatar
sof committed
494
\end{code}