ghc-9.6.3: The GHC API

Safe Haskell | Safe-Inferred
Language | Haskell2010

GHC.Tc.Gen.Foreign

Description

Typechecking `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.

Synopsis

- tcForeignImports :: [LForeignDecl GhcRn] -> TcM ([Id], [LForeignDecl GhcTc], Bag GlobalRdrElt)
- tcForeignExports :: [LForeignDecl GhcRn] -> TcM (LHsBinds GhcTc, [LForeignDecl GhcTc], Bag GlobalRdrElt)
- isForeignImport :: forall name. UnXRec name => LForeignDecl name -> Bool
- isForeignExport :: forall name. UnXRec name => LForeignDecl name -> Bool
- tcFImport :: LForeignDecl GhcRn -> TcM (Id, LForeignDecl GhcTc, Bag GlobalRdrElt)
- tcFExport :: ForeignDecl GhcRn -> TcM (LHsBind GhcTc, ForeignDecl GhcTc, Bag GlobalRdrElt)
- tcForeignImports' :: [LForeignDecl GhcRn] -> TcM ([Id], [LForeignDecl GhcTc], Bag GlobalRdrElt)
- tcCheckFIType :: [Scaled Type] -> Type -> ForeignImport GhcRn -> TcM (ForeignImport GhcTc)
- checkCTarget :: ForeignImport GhcRn -> CCallTarget -> TcM ()
- checkForeignArgs :: (Type -> Validity' IllegalForeignTypeReason) -> [Scaled Type] -> TcM ()
- checkForeignRes :: Bool -> Bool -> (Type -> Validity' IllegalForeignTypeReason) -> Type -> TcM ()
- normaliseFfiType :: Type -> TcM (Reduction, Bag GlobalRdrElt)
- nonIOok :: Bool
- mustBeIO :: Bool
- checkSafe :: Bool
- noCheckSafe :: Bool
- tcForeignExports' :: [LForeignDecl GhcRn] -> TcM (LHsBinds GhcTc, [LForeignDecl GhcTc], Bag GlobalRdrElt)
- tcCheckFEType :: Type -> ForeignExport GhcRn -> TcM (ForeignExport GhcTc)

# Documentation

tcForeignImports :: [LForeignDecl GhcRn] -> TcM ([Id], [LForeignDecl GhcTc], Bag GlobalRdrElt) Source #

tcForeignExports :: [LForeignDecl GhcRn] -> TcM (LHsBinds GhcTc, [LForeignDecl GhcTc], Bag GlobalRdrElt) Source #

isForeignImport :: forall name. UnXRec name => LForeignDecl name -> Bool Source #

isForeignExport :: forall name. UnXRec name => LForeignDecl name -> Bool Source #

tcFImport :: LForeignDecl GhcRn -> TcM (Id, LForeignDecl GhcTc, Bag GlobalRdrElt) Source #

tcFExport :: ForeignDecl GhcRn -> TcM (LHsBind GhcTc, ForeignDecl GhcTc, Bag GlobalRdrElt) Source #

tcForeignImports' :: [LForeignDecl GhcRn] -> TcM ([Id], [LForeignDecl GhcTc], Bag GlobalRdrElt) Source #

tcCheckFIType :: [Scaled Type] -> Type -> ForeignImport GhcRn -> TcM (ForeignImport GhcTc) Source #

checkCTarget :: ForeignImport GhcRn -> CCallTarget -> TcM () Source #

checkForeignArgs :: (Type -> Validity' IllegalForeignTypeReason) -> [Scaled Type] -> TcM () Source #

checkForeignRes :: Bool -> Bool -> (Type -> Validity' IllegalForeignTypeReason) -> Type -> TcM () Source #

Check that the type has the form (IO t) or (t) , and that t satisfies the given predicate. 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.

normaliseFfiType :: Type -> TcM (Reduction, Bag GlobalRdrElt) Source #

nonIOok :: Bool Source #

mustBeIO :: Bool Source #

checkSafe :: Bool Source #

noCheckSafe :: Bool Source #

tcForeignExports' :: [LForeignDecl GhcRn] -> TcM (LHsBinds GhcTc, [LForeignDecl GhcTc], Bag GlobalRdrElt) Source #

tcCheckFEType :: Type -> ForeignExport GhcRn -> TcM (ForeignExport GhcTc) Source #