[project @ 2001-02-23 12:24:10 by simonmar]
[ghc-hetmet.git] / ghc / compiler / typecheck / TcForeign.lhs
index 6c51aee..875d974 100644 (file)
@@ -27,7 +27,7 @@ import RnHsSyn                ( RenamedHsDecl, RenamedForeignDecl )
 
 import TcMonad
 import TcEnv           ( newLocalId )
-import TcMonoType      ( tcHsBoxedSigType )
+import TcMonoType      ( tcHsLiftedSigType )
 import TcHsSyn         ( TcMonoBinds, TypecheckedForeignDecl,
                          TcForeignExportDecl )
 import TcExpr          ( tcPolyExpr )                  
@@ -40,7 +40,8 @@ import Type           ( splitFunTys
                        , splitTyConApp_maybe
                        , splitForAllTys
                        )
-import TysWiredIn      ( isFFIArgumentTy, isFFIResultTy, 
+import TysWiredIn      ( isFFIArgumentTy, isFFIImportResultTy, 
+                         isFFIExportResultTy,
                          isFFIExternalTy, isFFIDynArgumentTy, isFFIDynResultTy,
                          isFFILabelTy
                        )
@@ -84,7 +85,7 @@ tcFImport :: RenamedForeignDecl -> TcM (Id, TypecheckedForeignDecl)
 tcFImport fo@(ForeignDecl nm FoExport hs_ty Dynamic cconv src_loc) =
    tcAddSrcLoc src_loc              $
    tcAddErrCtxt (foreignDeclCtxt fo) $
-   tcHsBoxedSigType hs_ty           `thenTc`   \ sig_ty ->
+   tcHsLiftedSigType hs_ty          `thenTc`   \ sig_ty ->
    let
       -- drop the foralls before inspecting the structure
       -- of the foreign type.
@@ -99,7 +100,7 @@ tcFImport fo@(ForeignDecl nm FoExport hs_ty Dynamic cconv src_loc) =
 tcFImport fo@(ForeignDecl nm FoLabel hs_ty ext_nm cconv src_loc) =
    tcAddSrcLoc src_loc              $
    tcAddErrCtxt (foreignDeclCtxt fo) $
-   tcHsBoxedSigType hs_ty          `thenTc`    \ sig_ty ->
+   tcHsLiftedSigType hs_ty         `thenTc`    \ sig_ty ->
    let
       -- drop the foralls before inspecting the structure
       -- of the foreign type.
@@ -114,7 +115,7 @@ tcFImport fo@(ForeignDecl nm imp_exp@(FoImport isUnsafe) hs_ty ext_nm cconv src_
    tcAddSrcLoc src_loc              $
    tcAddErrCtxt (foreignDeclCtxt fo) $
 
-   tcHsBoxedSigType hs_ty                   `thenTc` \ ty ->
+   tcHsLiftedSigType hs_ty                  `thenTc` \ ty ->
     -- Check that the type has the right shape
     -- and that the argument and result types are acceptable.
    let
@@ -133,7 +134,7 @@ tcFExport fo@(ForeignDecl nm imp_exp hs_ty ext_nm cconv src_loc) =
    tcAddSrcLoc src_loc              $
    tcAddErrCtxt (foreignDeclCtxt fo) $
 
-   tcHsBoxedSigType hs_ty             `thenTc` \ sig_ty ->
+   tcHsLiftedSigType hs_ty            `thenTc` \ sig_ty ->
    tcPolyExpr (HsVar nm) sig_ty     `thenTc`    \ (rhs, lie, _, _, _) ->
 
    let
@@ -167,12 +168,14 @@ checkForeignImport is_dynamic is_safe ty args res
    case args of
      []     -> check False (illegalForeignTyErr True{-Arg-} ty)
      (x:xs) ->
+       getDOptsTc                                              `thenTc` \ dflags ->
         check (isFFIDynArgumentTy x) (illegalForeignTyErr True{-Arg-} ty) `thenTc_`
-        mapTc (checkForeignArg (isFFIArgumentTy is_safe)) xs   `thenTc_`
-       checkForeignRes True {-NonIO ok-} isFFIResultTy res
+        mapTc (checkForeignArg (isFFIArgumentTy dflags is_safe)) xs    `thenTc_`
+       checkForeignRes True {-NonIO ok-} (isFFIImportResultTy dflags) res
  | otherwise =
-     mapTc (checkForeignArg (isFFIArgumentTy is_safe)) args     `thenTc_`
-     checkForeignRes True {-NonIO ok-} isFFIResultTy res
+     getDOptsTc                                                           `thenTc` \ dflags ->
+     mapTc (checkForeignArg (isFFIArgumentTy dflags is_safe)) args `thenTc_`
+     checkForeignRes True {-NonIO ok-} (isFFIImportResultTy dflags) res
 
 checkForeignExport :: Bool -> Type -> [Type] -> Type -> TcM ()
 checkForeignExport is_dynamic ty args res
@@ -185,12 +188,13 @@ checkForeignExport is_dynamic ty args res
        case splitFunTys arg of
           (arg_tys, res_ty) -> 
                mapTc (checkForeignArg isFFIExternalTy) arg_tys `thenTc_`
-               checkForeignRes True {-NonIO ok-} isFFIResultTy res_ty `thenTc_`
+               checkForeignRes True {-NonIO ok-} isFFIExportResultTy res_ty
+                                                                `thenTc_`
                checkForeignRes False {-Must be IO-} isFFIDynResultTy res
      _      -> check False (illegalForeignTyErr True{-Arg-} ty)
  | otherwise =
      mapTc (checkForeignArg isFFIExternalTy) args              `thenTc_`
-     checkForeignRes True {-NonIO ok-} isFFIResultTy res
+     checkForeignRes True {-NonIO ok-} isFFIExportResultTy res
  
 checkForeignArg :: (Type -> Bool) -> Type -> TcM ()
 checkForeignArg pred ty = check (pred ty) (illegalForeignTyErr True{-Arg-} ty)